<!doctype html>
<html lang="en" data-color-mode="dark">
<head>
<meta charset="utf-8">
<title>Redis 备忘清单
 &#x26;  redis cheatsheet &#x26;  Quick Reference</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta description="Redis 备忘清单
===

本备忘单旨在快速理解 redis 所涉及的主要概念，提供了最常用的SQL语句，供您参考。

入门，为开发人员分享快速参考备忘单。">
<meta keywords="redis,reference,Quick,Reference,cheatsheet,cheat,sheet">
<link rel="icon" href="data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2024%2024%22%20fill%3D%22none%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20height%3D%221em%22%20width%3D%221em%22%3E%20%3Cpath%20d%3D%22m21.66%2010.44-.98%204.18c-.84%203.61-2.5%205.07-5.62%204.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2%201.17-2.42%203.16-3.07%206.5-2.28l1.67.39c4.19.98%205.47%203.05%204.49%207.23Z%22%20fill%3D%22%23c9d1d9%22%2F%3E%20%3Cpath%20d%3D%22M15.06%2019.39c-.62.42-1.4.77-2.35%201.08l-1.58.52c-3.97%201.28-6.06.21-7.35-3.76L2.5%2013.28c-1.28-3.97-.22-6.07%203.75-7.35l1.58-.52c.41-.13.8-.24%201.17-.31-.3.61-.54%201.35-.74%202.2l-.98%204.19c-.98%204.18.31%206.24%204.48%207.23l1.68.4c.58.14%201.12.23%201.62.27Zm2.43-8.88c-.06%200-.12-.01-.19-.02l-4.85-1.23a.75.75%200%200%201%20.37-1.45l4.85%201.23a.748.748%200%200%201-.18%201.47Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3Cpath%20d%3D%22M14.56%2013.89c-.06%200-.12-.01-.19-.02l-2.91-.74a.75.75%200%200%201%20.37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z%22%20fill%3D%22%23228e6c%22%20%2F%3E%20%3C%2Fsvg%3E" type="image/svg+xml">
<link rel="stylesheet" href="..\style\style.css">
<link rel="stylesheet" href="..\style\katex.css">
</head>
<body><nav class="header-nav"><div class="max-container"><a href="..\index.html" class="logo"><svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg" height="1em" width="1em">
  <path d="m21.66 10.44-.98 4.18c-.84 3.61-2.5 5.07-5.62 4.77-.5-.04-1.04-.13-1.62-.27l-1.68-.4c-4.17-.99-5.46-3.05-4.48-7.23l.98-4.19c.2-.85.44-1.59.74-2.2 1.17-2.42 3.16-3.07 6.5-2.28l1.67.39c4.19.98 5.47 3.05 4.49 7.23Z" fill="#c9d1d9"></path>
  <path d="M15.06 19.39c-.62.42-1.4.77-2.35 1.08l-1.58.52c-3.97 1.28-6.06.21-7.35-3.76L2.5 13.28c-1.28-3.97-.22-6.07 3.75-7.35l1.58-.52c.41-.13.8-.24 1.17-.31-.3.61-.54 1.35-.74 2.2l-.98 4.19c-.98 4.18.31 6.24 4.48 7.23l1.68.4c.58.14 1.12.23 1.62.27Zm2.43-8.88c-.06 0-.12-.01-.19-.02l-4.85-1.23a.75.75 0 0 1 .37-1.45l4.85 1.23a.748.748 0 0 1-.18 1.47Z" fill="#228e6c"></path>
  <path d="M14.56 13.89c-.06 0-.12-.01-.19-.02l-2.91-.74a.75.75 0 0 1 .37-1.45l2.91.74c.4.1.64.51.54.91-.08.34-.38.56-.72.56Z" fill="#228e6c"></path>
</svg>
<span class="title">Quick Reference</span></a><div class="menu"><a href="javascript:void(0);" class="searchbtn" id="searchbtn"><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><span>搜索</span><span>⌘K</span></a><a href="https://github.com/jaywcjlove/reference/blob/main/docs/redis.md" class="" target="__blank"><svg viewBox="0 0 36 36" fill="currentColor" height="1em" width="1em"><path d="m33 6.4-3.7-3.7a1.71 1.71 0 0 0-2.36 0L23.65 6H6a2 2 0 0 0-2 2v22a2 2 0 0 0 2 2h22a2 2 0 0 0 2-2V11.76l3-3a1.67 1.67 0 0 0 0-2.36ZM18.83 20.13l-4.19.93 1-4.15 9.55-9.57 3.23 3.23ZM29.5 9.43 26.27 6.2l1.85-1.85 3.23 3.23Z"></path><path fill="none" d="M0 0h36v36H0z"></path></svg><span>编辑</span></a><button id="darkMode" type="button"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="light" height="1em" width="1em">
  <path d="M6.995 12c0 2.761 2.246 5.007 5.007 5.007s5.007-2.246 5.007-5.007-2.246-5.007-5.007-5.007S6.995 9.239 6.995 12zM11 19h2v3h-2zm0-17h2v3h-2zm-9 9h3v2H2zm17 0h3v2h-3zM5.637 19.778l-1.414-1.414 2.121-2.121 1.414 1.414zM16.242 6.344l2.122-2.122 1.414 1.414-2.122 2.122zM6.344 7.759 4.223 5.637l1.415-1.414 2.12 2.122zm13.434 10.605-1.414 1.414-2.122-2.122 1.414-1.414z"></path>
</svg>
<svg xmlns="http://www.w3.org/2000/svg" fill="currentColor" viewBox="0 0 24 24" class="dark" height="1em" width="1em">
  <path d="M12 11.807A9.002 9.002 0 0 1 10.049 2a9.942 9.942 0 0 0-5.12 2.735c-3.905 3.905-3.905 10.237 0 14.142 3.906 3.906 10.237 3.905 14.143 0a9.946 9.946 0 0 0 2.735-5.119A9.003 9.003 0 0 1 12 11.807z"></path>
</svg>
</button><script src="../js/dark.js?v=1.4.1"></script><a href="https://github.com/jaywcjlove/reference" class="" target="__blank"><svg viewBox="0 0 16 16" fill="currentColor" height="1em" width="1em"><path d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.012 8.012 0 0 0 16 8c0-4.42-3.58-8-8-8z"></path></svg></a></div></div></nav><div class="wrap h1body-exist max-container"><header class="wrap-header h1wrap"><h1 id="redis-备忘清单"><svg viewBox="0 0 256 220" xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="xMidYMid" height="1em" width="1em">
  <path d="M245.97 168.943c-13.662 7.121-84.434 36.22-99.501 44.075-15.067 7.856-23.437 7.78-35.34 2.09-11.902-5.69-87.216-36.112-100.783-42.597C3.566 169.271 0 166.535 0 163.951v-25.876s98.05-21.345 113.879-27.024c15.828-5.679 21.32-5.884 34.79-.95 13.472 4.936 94.018 19.468 107.331 24.344l-.006 25.51c.002 2.558-3.07 5.364-10.024 8.988" fill="#912626"></path>
  <path d="M245.965 143.22c-13.661 7.118-84.431 36.218-99.498 44.072-15.066 7.857-23.436 7.78-35.338 2.09-11.903-5.686-87.214-36.113-100.78-42.594-13.566-6.485-13.85-10.948-.524-16.166 13.326-5.22 88.224-34.605 104.055-40.284 15.828-5.677 21.319-5.884 34.789-.948 13.471 4.934 83.819 32.935 97.13 37.81 13.316 4.881 13.827 8.9.166 16.02" fill="#C6302B"></path>
  <path d="M245.97 127.074c-13.662 7.122-84.434 36.22-99.501 44.078-15.067 7.853-23.437 7.777-35.34 2.087-11.903-5.687-87.216-36.112-100.783-42.597C3.566 127.402 0 124.67 0 122.085V96.206s98.05-21.344 113.879-27.023c15.828-5.679 21.32-5.885 34.79-.95C162.142 73.168 242.688 87.697 256 92.574l-.006 25.513c.002 2.557-3.07 5.363-10.024 8.987" fill="#912626"></path>
  <path d="M245.965 101.351c-13.661 7.12-84.431 36.218-99.498 44.075-15.066 7.854-23.436 7.777-35.338 2.087-11.903-5.686-87.214-36.112-100.78-42.594-13.566-6.483-13.85-10.947-.524-16.167C23.151 83.535 98.05 54.148 113.88 48.47c15.828-5.678 21.319-5.884 34.789-.949 13.471 4.934 83.819 32.933 97.13 37.81 13.316 4.88 13.827 8.9.166 16.02" fill="#C6302B"></path>
  <path d="M245.97 83.653c-13.662 7.12-84.434 36.22-99.501 44.078-15.067 7.854-23.437 7.777-35.34 2.087-11.903-5.687-87.216-36.113-100.783-42.595C3.566 83.98 0 81.247 0 78.665v-25.88s98.05-21.343 113.879-27.021c15.828-5.68 21.32-5.884 34.79-.95C162.142 29.749 242.688 44.278 256 49.155l-.006 25.512c.002 2.555-3.07 5.361-10.024 8.986" fill="#912626"></path>
  <path d="M245.965 57.93c-13.661 7.12-84.431 36.22-99.498 44.074-15.066 7.854-23.436 7.777-35.338 2.09C99.227 98.404 23.915 67.98 10.35 61.497-3.217 55.015-3.5 50.55 9.825 45.331 23.151 40.113 98.05 10.73 113.88 5.05c15.828-5.679 21.319-5.883 34.789-.948 13.471 4.935 83.819 32.934 97.13 37.811 13.316 4.876 13.827 8.897.166 16.017" fill="#C6302B"></path>
  <path d="m159.283 32.757-22.01 2.285-4.927 11.856-7.958-13.23-25.415-2.284 18.964-6.839-5.69-10.498 17.755 6.944 16.738-5.48-4.524 10.855 17.067 6.391m-28.251 57.518L89.955 73.238l58.86-9.035-17.783 26.072m-56.95-50.928c17.375 0 31.46 5.46 31.46 12.194 0 6.736-14.085 12.195-31.46 12.195s-31.46-5.46-31.46-12.195c0-6.734 14.085-12.194 31.46-12.194" fill="#FFF"></path>
  <path d="m185.295 35.998 34.836 13.766-34.806 13.753-.03-27.52" fill="#621B1C"></path>
  <path d="m146.755 51.243 38.54-15.245.03 27.519-3.779 1.478-34.791-13.752" fill="#9A2928"></path>
</svg>
<a aria-hidden="true" tabindex="-1" href="#redis-备忘清单"><span class="icon icon-link"></span></a>Redis 备忘清单</h1><div class="wrap-body">
<p>本备忘单旨在快速理解 <a href="https://redis.io/">redis</a> 所涉及的主要概念，提供了最常用的SQL语句，供您参考。</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
  <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#介绍">介绍</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#小试">小试</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#ping-测试">Ping 测试</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#经典-hello-world">经典 Hello World</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#数据类型">数据类型</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis服务相关的命令设置">Redis服务相关的命令设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#command">COMMAND</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#command-count">COMMAND COUNT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-1">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#command-getkeys">COMMAND GETKEYS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-2">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#command-info">COMMAND INFO</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-3">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#info">INFO</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-4">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#role">ROLE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-5">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#time">TIME</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-6">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis一些通用的命令">Redis一些通用的命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助-1">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#del">DEL</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-7">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#dump">DUMP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-8">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#exists">EXISTS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-9">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#expire">EXPIRE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-10">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#expireat">EXPIREAT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-11">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#keys">KEYS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-12">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#persist">PERSIST</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-13">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pexpire">PEXPIRE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-14">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pexpireat">PEXPIREAT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-15">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pttl">PTTL</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-16">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rename">RENAME</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-17">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#renamenx">RENAMENX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-18">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#touch">TOUCH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-19">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#ttl">TTL</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-20">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#type">TYPE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-21">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#unlink">UNLINK</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-22">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-连接相关的命令">Redis 连接相关的命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助-2">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#client-id">CLIENT ID</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-23">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#client-info">CLIENT INFO</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-24">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#echo">ECHO</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-25">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#ping">PING</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-26">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-字符串类型设置">Redis 字符串类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#append">APPEND</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-27">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bitcount">BITCOUNT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-28">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bitfield">BITFIELD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-29">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bitop">BITOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-30">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bitpos">BITPOS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-31">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#decr">DECR</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-32">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#decrby">DECRBY</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-33">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#get">GET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-34">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#getbit">GETBIT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-35">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#getrange">GETRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-36">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#getset">GETSET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-37">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#incr">INCR</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-38">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#msetnx">MSETNX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-39">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#incrbyfloat">INCRBYFLOAT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-40">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#mget">MGET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-41">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#mset">MSET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-42">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#incrby">INCRBY</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-43">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#psetex">PSETEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-44">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#set">SET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-45">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#setbit">SETBIT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-46">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#setex">SETEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-47">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#setnx">SETNX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-48">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#setrange">SETRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-49">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#strlen">STRLEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-50">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#stralgo">STRALGO</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-51">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-集合类型设置">Redis 集合类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sadd">SADD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-52">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#scard">SCARD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-53">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sdiff">SDIFF</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-54">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sdiffstore">SDIFFSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-55">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sinter">SINTER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-56">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sinterstore">SINTERSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-57">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sismember">SISMEMBER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-58">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#smismember">SMISMEMBER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-59">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#smembers">SMEMBERS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-60">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#smove">SMOVE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-61">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#spop">SPOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-62">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#srandmember">SRANDMEMBER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-63">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#srem">SREM</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-64">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sunion">SUNION</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-65">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#sunionstore">SUNIONSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-66">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-列表类型设置">Redis 列表类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助-3">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#blpop">BLPOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-67">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#brpop">BRPOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-68">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lindex">LINDEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-69">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#linsert">LINSERT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-70">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#llen">LLEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-71">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lpop">LPOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-72">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lpos">LPOS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-73">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lpush">LPUSH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-74">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lpushx">LPUSHX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-75">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lrange">LRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-76">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lrem">LREM</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-77">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lset">LSET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-78">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#ltrim">LTRIM</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-79">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rpop">RPOP</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-80">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rpoplpush">RPOPLPUSH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-81">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#lmove">LMOVE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-82">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rpush">RPUSH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-83">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#rpushx">RPUSHX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-84">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-哈希类型设置">Redis 哈希类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hdel">HDEL</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-85">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hexists">HEXISTS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-86">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hget">HGET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-87">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hgetall">HGETALL</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-88">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hincrby">HINCRBY</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-89">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hincrbyfloat">HINCRBYFLOAT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-90">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hkeys">HKEYS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-91">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hlen">HLEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-92">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hmget">HMGET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-93">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hmset">HMSET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-94">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hset">HSET</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-95">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hsetnx">HSETNX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-96">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hstrlen">HSTRLEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-97">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#hvals">HVALS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-98">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis-排序集类型设置">Redis 排序集类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bzpopmin">BZPOPMIN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-99">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#bzpopmax">BZPOPMAX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-100">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zadd">ZADD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-101">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zcard">ZCARD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-102">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zscore">ZSCORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-103">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zcount">ZCOUNT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-104">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zdiff">ZDIFF</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-105">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zdiffstore">ZDIFFSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-106">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zincrby">ZINCRBY</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-107">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zinter">ZINTER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-108">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zinterstore">ZINTERSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-109">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zlexcount">ZLEXCOUNT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-110">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zpopmax">ZPOPMAX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-111">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zpopmin">ZPOPMIN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-112">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrange">ZRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-113">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrangebylex">ZRANGEBYLEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-114">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrevrangebylex">ZREVRANGEBYLEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-115">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrangebyscore">ZRANGEBYSCORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-116">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrank">ZRANK</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-117">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrem">ZREM</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-118">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zremrangebylex">ZREMRANGEBYLEX</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-119">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zremrangebyrank">ZREMRANGEBYRANK</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-120">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zremrangebyscore">ZREMRANGEBYSCORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-121">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrevrange">ZREVRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-122">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrevrangebyscore">ZREVRANGEBYSCORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-123">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zrevrank">ZREVRANK</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-124">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zunion">ZUNION</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-125">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zmscore">ZMSCORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-126">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#zunionstore">ZUNIONSTORE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-127">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis地图坐标集类型设置">Redis地图坐标集类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#geoadd">GEOADD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-128">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#geohash">GEOHASH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-129">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#geopos">GEOPOS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-130">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#geodist">GEODIST</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-131">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#georadius">GEORADIUS</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-132">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#georadiusbymember">GEORADIUSBYMEMBER</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-133">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#geosearch">GEOSEARCH</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-134">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助-4">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis超文本日志类型设置">Redis超文本日志类型设置</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pfadd">PFADD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-135">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pfcount">PFCOUNT</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-136">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#pfmerge">PFMERGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-137">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#redis流命令">Redis流命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#一些引用可能有帮助-5">一些引用(可能有帮助)</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xadd">XADD</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-138">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xtrim">XTRIM</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-139">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xrange">XRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-140">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xrevrange">XREVRANGE</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-141">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xlen">XLEN</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-142">例子</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#xack">XACK</a><a aria-hidden="true" class="leve4 tocs-link" data-num="4" href="#例子-143">例子</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#集群方面的东西">集群方面的东西</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#节点集群">节点、集群</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#交易">交易</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#脚本">脚本</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#发布操作">发布操作</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="介绍"><a aria-hidden="true" tabindex="-1" href="#介绍"><span class="icon icon-link"></span></a>介绍</h3><div class="wrap-body">
<p>Redis 是一个 <code>key-value</code> 存储系统类似 Memcached</p>
<ul>
<li>它支持存储的 value 类型相对更多，包括string(字符串)、list(链表)、set(集合)、zset(sorted set 有序集合)和hash(哈希类型)</li>
<li>数据类型都支持 push/pop、add/remove 及取交集并集和差集及更丰富的操作</li>
</ul>
<p>启动 Redis</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ redis-server <span class="token operator">&#x26;</span>
</span></code></pre>
<p>使用 CLI 登陆 redis</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ redis-cli
</span></code></pre>
<p>使用 Telnet 的登陆 redis</p>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">$ telnet <span class="token number">127.0</span>.0.1 <span class="token number">6379</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="小试"><a aria-hidden="true" tabindex="-1" href="#小试"><span class="icon icon-link"></span></a>小试</h3><div class="wrap-body">
<h4 id="ping-测试"><a aria-hidden="true" tabindex="-1" href="#ping-测试"><span class="icon icon-link"></span></a>Ping 测试</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PING
</span><span class="code-line">PONG
</span></code></pre>
<h4 id="经典-hello-world"><a aria-hidden="true" tabindex="-1" href="#经典-hello-world"><span class="icon icon-link"></span></a>经典 Hello World</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello world"</span>
</span><span class="code-line">OK
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello world"</span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="数据类型"><a aria-hidden="true" tabindex="-1" href="#数据类型"><span class="icon icon-link"></span></a>数据类型</h3><div class="wrap-body">
<ul>
<li><a href="#redis-%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB%E5%9E%8B%E8%AE%BE%E7%BD%AE">Strings(字符串)</a></li>
<li><a href="#redis-%E5%88%97%E8%A1%A8%E7%B1%BB%E5%9E%8B%E8%AE%BE%E7%BD%AE">Lists(列表)</a></li>
<li><a href="#redis-%E5%93%88%E5%B8%8C%E7%B1%BB%E5%9E%8B%E8%AE%BE%E7%BD%AE">Hashes(哈希)</a></li>
<li><a href="#redis-%E9%9B%86%E5%90%88%E7%B1%BB%E5%9E%8B%E8%AE%BE%E7%BD%AE">Sets(集合)</a></li>
<li><a href="#redis-%E6%8E%92%E5%BA%8F%E9%9B%86%E7%B1%BB%E5%9E%8B%E8%AE%BE%E7%BD%AE">Sorted Sets(有序集合)</a></li>
</ul>
<p>Redis 支持以上 5 种数据类型</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis服务相关的命令设置"><a aria-hidden="true" tabindex="-1" href="#redis服务相关的命令设置"><span class="icon icon-link"></span></a>Redis服务相关的命令设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="command"><a aria-hidden="true" tabindex="-1" href="#command"><span class="icon icon-link"></span></a>COMMAND</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">COMMAND
</span></code></pre>
<h4 id="例子"><a aria-hidden="true" tabindex="-1" href="#例子"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> COMMAND
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"georadius_ro"</span>
</span><span class="code-line">     <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-6</span>
</span><span class="code-line">     <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"readonly"</span>
</span><span class="code-line">        <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"movablekeys"</span>
</span><span class="code-line">     <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">     <span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">     <span class="token number">6</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">     <span class="token number">7</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"@read"</span>
</span><span class="code-line">        <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"@geo"</span>
</span><span class="code-line">        <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"@slow"</span>
</span><span class="code-line">  <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"zpopmin"</span>
</span><span class="code-line">     <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-2</span>
</span><span class="code-line">     <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"write"</span>
</span><span class="code-line">        <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"fast"</span>
</span><span class="code-line">  <span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>
</span></code></pre>
<p>获取 Redis 命令详细信息的数组</p>
</div></div></div><div class="wrap h3body-not-exist col-span-2 row-span-4"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2 row-span-4-->













































































































































































































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/acl-load">ACL LOAD</a></td><td>从配置的 ACL 文件重新加载 ACL</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-save">ACL SAVE</a></td><td>将当前的 ACL 规则保存在配置的 ACL 文件中</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-list">ACL LIST</a></td><td>以 ACL 配置文件格式列出当前的 ACL 规则</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-users">ACL USERS</a></td><td>列出所有配置的ACL规则的用户名</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-getuser">ACL GETUSER</a></td><td>获取特定 ACL 用户的规则</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-setuser">ACL SETUSER</a></td><td>修改或创建特定 ACL 用户的规则</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-deluser">ACL DELUSER</a></td><td>删除指定的 ACL 用户和关联的规则</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-cat">ACL CAT</a></td><td>列出 ACL 类别或类别内的命令</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-genpass">ACL GENPASS</a></td><td>生成用于 ACL 用户的伪随机安全密码</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-whoami">ACL WHOAMI</a></td><td>返回关联到当前连接的用户的名称</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-log">ACL LOG</a></td><td>列出由于 ACL 到位而被拒绝的最新事件</td></tr><tr><td align="left"><a href="https://redis.io/commands/acl-help">ACL HELP</a></td><td>显示有关ACL访问控制的帮助信息</td></tr><tr><td align="left"><a href="https://redis.io/commands/bgrewriteaof">BGREWRITEAOF</a></td><td>异步重写 append-only 文件</td></tr><tr><td align="left"><a href="https://redis.io/commands/bgsave">BGSAVE</a></td><td>将数据集异步保存到磁盘</td></tr><tr><td align="left"><a href="https://redis.io/commands/config-get">CONFIG GET</a></td><td>获取配置参数的值</td></tr><tr><td align="left"><a href="https://redis.io/commands/config-rewrite">CONFIG REWRITE</a></td><td>用内存中的配置重写配置文件</td></tr><tr><td align="left"><a href="https://redis.io/commands/config-set">CONFIG SET</a></td><td>将配置参数设置为给定值</td></tr><tr><td align="left"><a href="https://redis.io/commands/config-resetstat">CONFIG RESETSTAT</a></td><td>重置 INFO 返回的统计数据</td></tr><tr><td align="left"><a href="https://redis.io/commands/dbsize">DBSIZE</a></td><td>返回所选数据库中的键数</td></tr><tr><td align="left"><a href="https://redis.io/commands/debug-object">DEBUG OBJECT</a></td><td>获取某个key的调试信息</td></tr><tr><td align="left"><a href="https://redis.io/commands/debug-segfault">DEBUG SEGFAULT</a></td><td>使服务器崩溃</td></tr><tr><td align="left"><a href="https://redis.io/commands/flushall">FLUSHALL</a></td><td>从所有数据库中删除所有密钥</td></tr><tr><td align="left"><a href="https://redis.io/commands/flushdb">FLUSHDB</a></td><td>从当前数据库中删除所有键</td></tr><tr><td align="left"><a href="https://redis.io/commands/lolwut">LOLWUT</a></td><td>显示一些计算机信息和 Redis 版本</td></tr><tr><td align="left"><a href="https://redis.io/commands/lastsave">LASTSAVE</a></td><td>获取上次成功保存到磁盘的 UNIX 时间戳</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-doctor">MEMORY DOCTOR</a></td><td>输出内存问题报告</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-help">MEMORY HELP</a></td><td>显示有关内存的使用帮助</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-malloc-stats">MEMORY MALLOC-STATS</a></td><td>显示分配器内部统计</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-purge">MEMORY PURGE</a></td><td>要求分配器释放内存</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-stats">MEMORY STATS</a></td><td>显示内存使用详情(该死，运维的我经常用到)</td></tr><tr><td align="left"><a href="https://redis.io/commands/memory-usage">MEMORY USAGE</a></td><td>估计一个键的内存使用</td></tr><tr><td align="left"><a href="https://redis.io/commands/module-list">MODULE LIST</a></td><td>列出服务器加载的所有模块</td></tr><tr><td align="left"><a href="https://redis.io/commands/module-load">MODULE LOAD</a></td><td>加载模块</td></tr><tr><td align="left"><a href="https://redis.io/commands/module-unload">MODULE UNLOAD</a></td><td>卸载模块</td></tr><tr><td align="left"><a href="https://redis.io/commands/monitor">MONITOR</a></td><td>实时监听服务器收到的所有请求</td></tr><tr><td align="left"><a href="https://redis.io/commands/save">SAVE</a></td><td>将数据集同步保存到磁盘</td></tr><tr><td align="left"><a href="https://redis.io/commands/shutdown">SHUTDOWN</a></td><td>将数据集同步保存到磁盘，然后关闭服务器</td></tr><tr><td align="left"><a href="https://redis.io/commands/slaveof"><del>SLAVEOF</del></a></td><td>使服务器成为另一个实例的副本，或将其提升为主服务器<br> <em>(从Redis 5开始<red>弃用</red>，改成 <code>REPLICAOF</code>了)</em></td></tr><tr><td align="left"><a href="https://redis.io/commands/replicaof">REPLICAOF</a></td><td>使服务器成为另一个实例的副本，或将其提升为主服务器</td></tr><tr><td align="left"><a href="https://redis.io/commands/slowlog">SLOWLOG</a></td><td>管理 Redis 慢查询日志</td></tr><tr><td align="left"><a href="https://redis.io/commands/swapdb">SWAPDB</a></td><td>交换两个Redis数据库</td></tr><tr><td align="left"><a href="https://redis.io/commands/sync">SYNC</a></td><td>用于复制的内部命令(主)</td></tr><tr><td align="left"><a href="https://redis.io/commands/psync">PSYNC</a></td><td>用于复制的内部命令(备)</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-doctor">LATENCY DOCTOR</a></td><td>返回人类可读的延迟分析报告</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-graph">LATENCY GRAPH</a></td><td>返回事件的延迟图</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-history">LATENCY HISTORY</a></td><td>返回事件的时间戳延迟样本</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-latest">LATENCY LATEST</a></td><td>返回所有事件的最新延迟样本</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-reset">LATENCY RESET</a></td><td>重置一个或多个事件的延迟数据</td></tr><tr><td align="left"><a href="https://redis.io/commands/latency-help">LATENCY HELP</a></td><td>显示有关不同子命令的有用文本</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="command-count"><a aria-hidden="true" tabindex="-1" href="#command-count"><span class="icon icon-link"></span></a>COMMAND COUNT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">COMMAND COUNT
</span></code></pre>
<h4 id="例子-1"><a aria-hidden="true" tabindex="-1" href="#例子-1"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> COMMAND COUNT
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">217</span>
</span></code></pre>
<p>获取 Redis 命令总数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="command-getkeys"><a aria-hidden="true" tabindex="-1" href="#command-getkeys"><span class="icon icon-link"></span></a>COMMAND GETKEYS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">COMMAND GETKEYS
</span></code></pre>
<h4 id="例子-2"><a aria-hidden="true" tabindex="-1" href="#例子-2"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> COMMAND GETKEYS MSET a b c d e f
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line">redis<span class="token operator">></span> COMMAND GETKEYS EVAL <span class="token string">"not consulted"</span> <span class="token number">3</span> key1 key2 key3 arg1 arg2 arg3 argN
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"key1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"key2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"key3"</span>
</span><span class="code-line">redis<span class="token operator">></span> COMMAND GETKEYS SORT mylist ALPHA STORE outlist
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"mylist"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"outlist"</span>
</span></code></pre>
<p>给定完整的 Redis 命令提取密钥</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="command-info"><a aria-hidden="true" tabindex="-1" href="#command-info"><span class="icon icon-link"></span></a>COMMAND INFO</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">COMMAND INFO command-name [command-name ...]
</span></code></pre>
<h4 id="例子-3"><a aria-hidden="true" tabindex="-1" href="#例子-3"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> COMMAND INFO get <span class="token builtin class-name">set</span> <span class="token builtin class-name">eval</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"get"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">   <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"readonly"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"fast"</span>
</span><span class="code-line">   <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">6</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">7</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"@read"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"@string"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"@fast"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"set"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-3</span>
</span><span class="code-line">   <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"write"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"denyoom"</span>
</span><span class="code-line">   <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">6</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">   <span class="token number">7</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"@write"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"@string"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"@slow"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"eval"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-3</span>
</span><span class="code-line">   <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"noscript"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"movablekeys"</span>
</span><span class="code-line">   <span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">   <span class="token number">5</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">   <span class="token number">6</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">   <span class="token number">7</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"@slow"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"@scripting"</span>
</span></code></pre>
<p>获取特定 Redis 命令详细信息的数组</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="info"><a aria-hidden="true" tabindex="-1" href="#info"><span class="icon icon-link"></span></a>INFO</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">INFO [section]
</span></code></pre>
<h4 id="例子-4"><a aria-hidden="true" tabindex="-1" href="#例子-4"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> INFO
</span><span class="code-line"><span class="token comment"># Server</span>
</span><span class="code-line">redis_version:6.1.240
</span><span class="code-line">redis_git_sha1:00000000
</span><span class="code-line">redis_git_dirty:0
</span><span class="code-line">redis_build_id:a26db646ea64a07c
</span><span class="code-line">redis_mode:standalone
</span><span class="code-line">os:Linux <span class="token number">5.4</span>.0-1017-aws x86_64
</span><span class="code-line"><span class="token punctuation">..</span><span class="token punctuation">..</span><span class="token punctuation">..</span>
</span></code></pre>
<p>获取有关服务器的信息和统计信息</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="role"><a aria-hidden="true" tabindex="-1" href="#role"><span class="icon icon-link"></span></a>ROLE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ROLE
</span></code></pre>
<h4 id="例子-5"><a aria-hidden="true" tabindex="-1" href="#例子-5"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ROLE
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"master"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>返回实例在复制上下文中的角色</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="time"><a aria-hidden="true" tabindex="-1" href="#time"><span class="icon icon-link"></span></a>TIME</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">TIME
</span></code></pre>
<h4 id="例子-6"><a aria-hidden="true" tabindex="-1" href="#例子-6"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> TIME
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040690"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"558952"</span>
</span><span class="code-line">redis<span class="token operator">></span> TIME
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040690"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"559206"</span>
</span></code></pre>
<p>返回当前服务器时间</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis一些通用的命令"><a aria-hidden="true" tabindex="-1" href="#redis一些通用的命令"><span class="icon icon-link"></span></a>Redis一些通用的命令</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助-1"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助-1"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">









































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/copy">COPY</a></td><td>复制键值对</td></tr><tr><td align="left"><a href="https://redis.io/commands/migrate">MIGRATE</a></td><td>以原子方式将键值对从 Redis 实例传输到另一个实例</td></tr><tr><td align="left"><a href="https://redis.io/commands/move">MOVE</a></td><td>将键值对移动到另一个数据库</td></tr><tr><td align="left"><a href="https://redis.io/commands/object">OBJECT</a></td><td>检查 Redis 对象的内部结构</td></tr><tr><td align="left"><a href="https://redis.io/commands/restore">RESTORE</a></td><td>使用提供的序列化值创建键值对，之前使用 DUMP 获得</td></tr><tr><td align="left"><a href="https://redis.io/commands/sort">SORT</a></td><td>对列表、集合或有序集合中的元素进行排序</td></tr><tr><td align="left"><a href="https://redis.io/commands/wait">WAIT</a></td><td>等待在当前连接的上下文中发送的所有写命令的同步复制</td></tr><tr><td align="left"><a href="https://redis.io/commands/scan">SCAN</a></td><td>增量迭代键空间</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="del"><a aria-hidden="true" tabindex="-1" href="#del"><span class="icon icon-link"></span></a>DEL</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">DEL key [key ...]
</span></code></pre>
<h4 id="例子-7"><a aria-hidden="true" tabindex="-1" href="#例子-7"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> DEL key1 key2 key3
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>删除键值对</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="dump"><a aria-hidden="true" tabindex="-1" href="#dump"><span class="icon icon-link"></span></a>DUMP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">DUMP key
</span></code></pre>
<h4 id="例子-8"><a aria-hidden="true" tabindex="-1" href="#例子-8"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token number">10</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> DUMP mykey
</span><span class="code-line"><span class="token string">"<span class="token entity" title="\u0000">\u0000</span><span class="token entity" title="\xC0">\xC0</span><span class="token entity" title="\n">\n</span><span class="token entity" title="\t">\t</span><span class="token entity" title="\u0000">\u0000</span><span class="token entity" title="\xBE">\xBE</span>m<span class="token entity" title="\u0006">\u0006</span><span class="token entity" title="\x89">\x89</span>Z(<span class="token entity" title="\u0000">\u0000</span><span class="token entity" title="\n">\n</span>"</span>
</span></code></pre>
<p>返回存储在指定键中的值的序列化版本</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="exists"><a aria-hidden="true" tabindex="-1" href="#exists"><span class="icon icon-link"></span></a>EXISTS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">EXISTS key [key ...]
</span></code></pre>
<h4 id="例子-9"><a aria-hidden="true" tabindex="-1" href="#例子-9"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXISTS key1
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> EXISTS nosuchkey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXISTS key1 key2 nosuchkey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>判断键值对是否存在</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="expire"><a aria-hidden="true" tabindex="-1" href="#expire"><span class="icon icon-link"></span></a>EXPIRE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">EXPIRE key seconds
</span></code></pre>
<h4 id="例子-10"><a aria-hidden="true" tabindex="-1" href="#例子-10"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXPIRE mykey <span class="token number">10</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-1</span>
</span></code></pre>
<p>设置键值对的生存时间(以秒为单位)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="expireat"><a aria-hidden="true" tabindex="-1" href="#expireat"><span class="icon icon-link"></span></a>EXPIREAT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">EXPIREAT key timestamp
</span></code></pre>
<h4 id="例子-11"><a aria-hidden="true" tabindex="-1" href="#例子-11"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXISTS mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> EXPIREAT mykey <span class="token number">1293840000</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> EXISTS mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>将键值对的到期时间设置为 UNIX 时间戳</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="keys"><a aria-hidden="true" tabindex="-1" href="#keys"><span class="icon icon-link"></span></a>KEYS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">KEYS pattern
</span></code></pre>
<h4 id="例子-12"><a aria-hidden="true" tabindex="-1" href="#例子-12"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> MSET firstname Jack lastname Stuntman age <span class="token number">35</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> KEYS *name*
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"firstname"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"lastname"</span>
</span><span class="code-line">redis<span class="token operator">></span> KEYS a??
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"age"</span>
</span><span class="code-line">redis<span class="token operator">></span> KEYS *
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"firstname"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"age"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"lastname"</span>
</span></code></pre>
<p>查找与给定模式匹配的所有键</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="persist"><a aria-hidden="true" tabindex="-1" href="#persist"><span class="icon icon-link"></span></a>PERSIST</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">PERSIST key
</span></code></pre>
<h4 id="例子-13"><a aria-hidden="true" tabindex="-1" href="#例子-13"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXPIRE mykey <span class="token number">10</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span><span class="code-line">redis<span class="token operator">></span> PERSIST mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-1</span>
</span></code></pre>
<p>从键值对中删除过期时间</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pexpire"><a aria-hidden="true" tabindex="-1" href="#pexpire"><span class="icon icon-link"></span></a>PEXPIRE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">PEXPIRE key milliseconds
</span></code></pre>
<h4 id="例子-14"><a aria-hidden="true" tabindex="-1" href="#例子-14"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> PEXPIRE mykey <span class="token number">1500</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PTTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1499</span>
</span></code></pre>
<p>设置键的生存时间(以毫秒为单位)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pexpireat"><a aria-hidden="true" tabindex="-1" href="#pexpireat"><span class="icon icon-link"></span></a>PEXPIREAT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">PEXPIREAT key milliseconds-timestamp
</span></code></pre>
<h4 id="例子-15"><a aria-hidden="true" tabindex="-1" href="#例子-15"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> PEXPIREAT mykey <span class="token number">1555555555005</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-2</span>
</span><span class="code-line">redis<span class="token operator">></span> PTTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-2</span>
</span></code></pre>
<p>将键值对的到期时间设置为以毫秒为单位指定的 UNIX 时间戳</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pttl"><a aria-hidden="true" tabindex="-1" href="#pttl"><span class="icon icon-link"></span></a>PTTL</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">PTTL key
</span></code></pre>
<h4 id="例子-16"><a aria-hidden="true" tabindex="-1" href="#例子-16"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXPIRE mykey <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PTTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1000</span>
</span></code></pre>
<p>以毫秒为单位获取键值对的生存时间</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="rename"><a aria-hidden="true" tabindex="-1" href="#rename"><span class="icon icon-link"></span></a>RENAME</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RENAME key newkey
</span></code></pre>
<h4 id="例子-17"><a aria-hidden="true" tabindex="-1" href="#例子-17"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> RENAME mykey myotherkey
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET myotherkey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>重命名键值对</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="renamenx"><a aria-hidden="true" tabindex="-1" href="#renamenx"><span class="icon icon-link"></span></a>RENAMENX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RENAMENX key newkey
</span></code></pre>
<h4 id="例子-18"><a aria-hidden="true" tabindex="-1" href="#例子-18"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET myotherkey <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> RENAMENX mykey myotherkey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> GET myotherkey
</span><span class="code-line"><span class="token string">"World"</span>
</span></code></pre>
<p>重命名键值对，仅当新键值对不存在时</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="touch"><a aria-hidden="true" tabindex="-1" href="#touch"><span class="icon icon-link"></span></a>TOUCH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">TOUCH key [key ...]
</span></code></pre>
<h4 id="例子-19"><a aria-hidden="true" tabindex="-1" href="#例子-19"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> TOUCH key1 key2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>更改键值对的最后访问时间。返回指定的现有键的数量</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="ttl"><a aria-hidden="true" tabindex="-1" href="#ttl"><span class="icon icon-link"></span></a>TTL</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">TTL key
</span></code></pre>
<h4 id="例子-20"><a aria-hidden="true" tabindex="-1" href="#例子-20"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> EXPIRE mykey <span class="token number">10</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span></code></pre>
<p>获得一个键的值的时间(有点绕口，但意思是对的)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="type"><a aria-hidden="true" tabindex="-1" href="#type"><span class="icon icon-link"></span></a>TYPE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">TYPE key
</span></code></pre>
<h4 id="例子-21"><a aria-hidden="true" tabindex="-1" href="#例子-21"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"value"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSH key2 <span class="token string">"value"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key3 <span class="token string">"value"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> TYPE key1
</span><span class="code-line"><span class="token string">"string"</span>
</span><span class="code-line">redis<span class="token operator">></span> TYPE key2
</span><span class="code-line"><span class="token string">"list"</span>
</span><span class="code-line">redis<span class="token operator">></span> TYPE key3
</span><span class="code-line"><span class="token string">"set"</span>
</span></code></pre>
<p>确定存储在键中的类型</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="unlink"><a aria-hidden="true" tabindex="-1" href="#unlink"><span class="icon icon-link"></span></a>UNLINK</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">UNLINK key [key ...]
</span></code></pre>
<h4 id="例子-22"><a aria-hidden="true" tabindex="-1" href="#例子-22"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> UNLINK key1 key2 key3
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>在另一个线程中异步删除一个键。否则它就像 DEL，但不是阻塞的</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-连接相关的命令"><a aria-hidden="true" tabindex="-1" href="#redis-连接相关的命令"><span class="icon icon-link"></span></a>Redis 连接相关的命令</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助-2"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助-2"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->





































































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/auth">AUTH</a></td><td>向服务器进行身份验证</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-caching">CLIENT CACHING</a></td><td>指示服务器在下一个请求中是否跟踪键</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-kill">CLIENT KILL</a></td><td>终止客户端的连接</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-list">CLIENT LIST</a></td><td>获取客户端连接列表</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-getname">CLIENT GETNAME</a></td><td>获取当前连接名称</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-getredir">CLIENT GETREDIR</a></td><td>获取跟踪通知重定向客户端 ID(如果有)</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-pause">CLIENT PAUSE</a></td><td>停止处理来自客户端的命令一段时间</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-reply">CLIENT REPLY</a></td><td>指示服务器是否回复命令</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-setname">CLIENT SETNAME</a></td><td>设置当前连接名称</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-tracking">CLIENT TRACKING</a></td><td>启用或禁用服务器辅助客户端缓存支持</td></tr><tr><td align="left"><a href="https://redis.io/commands/client-unblock">CLIENT UNBLOCK</a></td><td>取消阻止来自不同连接的阻塞命令中阻塞的客户端</td></tr><tr><td align="left"><a href="https://redis.io/commands/hello">HELLO</a></td><td>切换Redis协议</td></tr><tr><td align="left"><a href="https://redis.io/commands/quit">QUIT</a></td><td>关闭连接</td></tr><tr><td align="left"><a href="https://redis.io/commands/reset">RESET</a></td><td>重置连接</td></tr><tr><td align="left"><a href="https://redis.io/commands/select">SELECT</a></td><td>更改为当前连接选择的数据库</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="client-id"><a aria-hidden="true" tabindex="-1" href="#client-id"><span class="icon icon-link"></span></a>CLIENT ID</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">CLIENT ID
</span></code></pre>
<h4 id="例子-23"><a aria-hidden="true" tabindex="-1" href="#例子-23"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> CLIENT ID
</span><span class="code-line">ERR Unknown or disabled <span class="token builtin class-name">command</span> <span class="token string">'CLIENT'</span>
</span></code></pre>
<p>返回当前连接的客户端 ID</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="client-info"><a aria-hidden="true" tabindex="-1" href="#client-info"><span class="icon icon-link"></span></a>CLIENT INFO</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">CLIENT INFO
</span></code></pre>
<h4 id="例子-24"><a aria-hidden="true" tabindex="-1" href="#例子-24"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> CLIENT INFO
</span><span class="code-line"><span class="token string">"id=55542 addr=127.0.0.1:58710 laddr=127.0.0.1:6379 fd=8 name= age=114920 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=26 qbuf-free=40928 argv-mem=10 obl=0 oll=0 omem=0 tot-mem=61466 events=r cmd=client user=default redir=-1<span class="token entity" title="\n">\n</span>"</span>
</span></code></pre>
<p>返回有关当前客户端连接的信息。</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="echo"><a aria-hidden="true" tabindex="-1" href="#echo"><span class="icon icon-link"></span></a>ECHO</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">ECHO message
</span></code></pre>
<h4 id="例子-25"><a aria-hidden="true" tabindex="-1" href="#例子-25"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ECHO <span class="token string">"Hello World!"</span>
</span><span class="code-line"><span class="token string">"Hello World!"</span>
</span></code></pre>
<p>回显给定的字符串</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="ping"><a aria-hidden="true" tabindex="-1" href="#ping"><span class="icon icon-link"></span></a>PING</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">PING <span class="token punctuation">[</span>message<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-26"><a aria-hidden="true" tabindex="-1" href="#例子-26"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PING
</span><span class="code-line"><span class="token string">"PONG"</span>
</span><span class="code-line">redis<span class="token operator">></span> PING <span class="token string">"hello world"</span>
</span><span class="code-line"><span class="token string">"hello world"</span>
</span></code></pre>
<p>ping 服务器</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-字符串类型设置"><a aria-hidden="true" tabindex="-1" href="#redis-字符串类型设置"><span class="icon icon-link"></span></a>Redis 字符串类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="append"><a aria-hidden="true" tabindex="-1" href="#append"><span class="icon icon-link"></span></a>APPEND</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">APPEND key value
</span></code></pre>
<h4 id="例子-27"><a aria-hidden="true" tabindex="-1" href="#例子-27"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> EXISTS mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> APPEND mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> APPEND mykey <span class="token string">" World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">11</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello World"</span>
</span></code></pre>
<p>将值附加到键,可以理解为追加作用</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bitcount"><a aria-hidden="true" tabindex="-1" href="#bitcount"><span class="icon icon-link"></span></a>BITCOUNT</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">BITCOUNT key <span class="token punctuation">[</span>start end<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-28"><a aria-hidden="true" tabindex="-1" href="#例子-28"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"foobar"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> BITCOUNT mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">26</span>
</span><span class="code-line">redis<span class="token operator">></span> BITCOUNT mykey <span class="token number">0</span> <span class="token number">0</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
</span><span class="code-line">redis<span class="token operator">></span> BITCOUNT mykey <span class="token number">1</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span></code></pre>
<p>计算字符串中的集合位</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bitfield"><a aria-hidden="true" tabindex="-1" href="#bitfield"><span class="icon icon-link"></span></a>BITFIELD</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">BITFIELD key <span class="token punctuation">[</span>GET <span class="token builtin class-name">type</span> offset<span class="token punctuation">]</span> <span class="token punctuation">[</span>SET <span class="token builtin class-name">type</span> offset value<span class="token punctuation">]</span> 
</span><span class="code-line"><span class="token punctuation">[</span>INCRBY <span class="token builtin class-name">type</span> offset increment<span class="token punctuation">]</span> <span class="token punctuation">[</span>OVERFLOW WRAP<span class="token operator">|</span>SAT<span class="token operator">|</span>FAIL<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-29"><a aria-hidden="true" tabindex="-1" href="#例子-29"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> BITFIELD mykey INCRBY i5 <span class="token number">100</span> <span class="token number">1</span> GET u4 <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>对字符串执行任意位域整数运算</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bitop"><a aria-hidden="true" tabindex="-1" href="#bitop"><span class="icon icon-link"></span></a>BITOP</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">BITOP operation destkey key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-30"><a aria-hidden="true" tabindex="-1" href="#例子-30"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"foobar"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"abcdef"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> BITOP AND dest key1 key2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span><span class="code-line">redis<span class="token operator">></span> GET dest
</span><span class="code-line"><span class="token string">"<span class="token variable"><span class="token variable">`</span><span class="token function">bc</span><span class="token variable">`</span></span>ab"</span>
</span></code></pre>
<p>在字符串之间执行按位运算</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bitpos"><a aria-hidden="true" tabindex="-1" href="#bitpos"><span class="icon icon-link"></span></a>BITPOS</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">BITPOS key bit <span class="token punctuation">[</span>start<span class="token punctuation">]</span> <span class="token punctuation">[</span>end<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-31"><a aria-hidden="true" tabindex="-1" href="#例子-31"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"<span class="token entity" title="\xff">\xff</span><span class="token entity" title="\xf0">\xf0</span><span class="token entity" title="\x00">\x00</span>"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> BITPOS mykey <span class="token number">0</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">12</span>
</span><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"<span class="token entity" title="\x00">\x00</span><span class="token entity" title="\xff">\xff</span><span class="token entity" title="\xf0">\xf0</span>"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> BITPOS mykey <span class="token number">1</span> <span class="token number">0</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">8</span>
</span><span class="code-line">redis<span class="token operator">></span> BITPOS mykey <span class="token number">1</span> <span class="token number">2</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">16</span>
</span><span class="code-line">redis<span class="token operator">></span> <span class="token builtin class-name">set</span> mykey <span class="token string">"<span class="token entity" title="\x00">\x00</span><span class="token entity" title="\x00">\x00</span><span class="token entity" title="\x00">\x00</span>"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> BITPOS mykey <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-1</span>
</span></code></pre>
<p>查找字符串中设置或清除的第一位</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="decr"><a aria-hidden="true" tabindex="-1" href="#decr"><span class="icon icon-link"></span></a>DECR</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">DECR key
</span></code></pre>
<h4 id="例子-32"><a aria-hidden="true" tabindex="-1" href="#例子-32"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"10"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> DECR mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">9</span>
</span><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"234293482390480948029348230948"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> DECR mykey
</span><span class="code-line">ERR ERR value is not an integer or out of range
</span></code></pre>
<p>将键的整数值减一</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="decrby"><a aria-hidden="true" tabindex="-1" href="#decrby"><span class="icon icon-link"></span></a>DECRBY</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">DECRBY key decrement
</span></code></pre>
<h4 id="例子-33"><a aria-hidden="true" tabindex="-1" href="#例子-33"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"10"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> DECRBY mykey <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span></code></pre>
<p>将键的整数值减去给定的数字</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="get"><a aria-hidden="true" tabindex="-1" href="#get"><span class="icon icon-link"></span></a>GET</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">GET key
</span></code></pre>
<h4 id="例子-34"><a aria-hidden="true" tabindex="-1" href="#例子-34"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GET nonexisting
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>获取key的值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="getbit"><a aria-hidden="true" tabindex="-1" href="#getbit"><span class="icon icon-link"></span></a>GETBIT</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">GETBIT key offset
</span></code></pre>
<h4 id="例子-35"><a aria-hidden="true" tabindex="-1" href="#例子-35"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SETBIT mykey <span class="token number">7</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> GETBIT mykey <span class="token number">0</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> GETBIT mykey <span class="token number">7</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> GETBIT mykey <span class="token number">100</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>返回存储在 <code>key</code> 处的字符串值中 <code>offset</code> 处的位值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="getrange"><a aria-hidden="true" tabindex="-1" href="#getrange"><span class="icon icon-link"></span></a>GETRANGE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">GETRANGE key start end
</span></code></pre>
<h4 id="例子-36"><a aria-hidden="true" tabindex="-1" href="#例子-36"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"This is a string"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> GETRANGE mykey <span class="token number">0</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token string">"This"</span>
</span><span class="code-line">redis<span class="token operator">></span> GETRANGE mykey <span class="token parameter variable">-3</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token string">"ing"</span>
</span><span class="code-line">redis<span class="token operator">></span> GETRANGE mykey <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token string">"This is a string"</span>
</span><span class="code-line">redis<span class="token operator">></span> GETRANGE mykey <span class="token number">10</span> <span class="token number">100</span>
</span><span class="code-line"><span class="token string">"string"</span>
</span></code></pre>
<p>获取存储在键中的字符串的子字符串</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="getset"><a aria-hidden="true" tabindex="-1" href="#getset"><span class="icon icon-link"></span></a>GETSET</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">GETSET key value
</span></code></pre>
<h4 id="例子-37"><a aria-hidden="true" tabindex="-1" href="#例子-37"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> INCR mycounter
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> GETSET mycounter <span class="token string">"0"</span>
</span><span class="code-line"><span class="token string">"1"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mycounter
</span><span class="code-line"><span class="token string">"0"</span>
</span></code></pre>
<p>设置键的字符串值并返回其旧值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="incr"><a aria-hidden="true" tabindex="-1" href="#incr"><span class="icon icon-link"></span></a>INCR</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">INCR key
</span></code></pre>
<h4 id="例子-38"><a aria-hidden="true" tabindex="-1" href="#例子-38"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"10"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> INCR mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">11</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"11"</span>
</span></code></pre>
<p>将键的整数值加一</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="msetnx"><a aria-hidden="true" tabindex="-1" href="#msetnx"><span class="icon icon-link"></span></a>MSETNX</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">MSETNX key value <span class="token punctuation">[</span>key value <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-39"><a aria-hidden="true" tabindex="-1" href="#例子-39"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> MSETNX key1 <span class="token string">"Hello"</span> key2 <span class="token string">"there"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> MSETNX key2 <span class="token string">"new"</span> key3 <span class="token string">"world"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> MGET key1 key2 key3
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"there"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>仅当不存在任何键时，将多个键设置为多个值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="incrbyfloat"><a aria-hidden="true" tabindex="-1" href="#incrbyfloat"><span class="icon icon-link"></span></a>INCRBYFLOAT</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">INCRBYFLOAT key increment
</span></code></pre>
<h4 id="例子-40"><a aria-hidden="true" tabindex="-1" href="#例子-40"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token number">10.50</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> INCRBYFLOAT mykey <span class="token number">0.1</span>
</span><span class="code-line"><span class="token string">"10.6"</span>
</span><span class="code-line">redis<span class="token operator">></span> INCRBYFLOAT mykey <span class="token parameter variable">-5</span>
</span><span class="code-line"><span class="token string">"5.6"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token number">5</span>.0e3
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> INCRBYFLOAT mykey <span class="token number">2</span>.0e2
</span><span class="code-line"><span class="token string">"5200"</span>
</span></code></pre>
<p>将键的浮点值增加给定的数量</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="mget"><a aria-hidden="true" tabindex="-1" href="#mget"><span class="icon icon-link"></span></a>MGET</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">MGET key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-41"><a aria-hidden="true" tabindex="-1" href="#例子-41"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> MGET key1 key2 nonexisting
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>获取所有给定键的值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="mset"><a aria-hidden="true" tabindex="-1" href="#mset"><span class="icon icon-link"></span></a>MSET</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">MSET key value <span class="token punctuation">[</span>key value <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-42"><a aria-hidden="true" tabindex="-1" href="#例子-42"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> MSET key1 <span class="token string">"Hello"</span> key2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET key1
</span><span class="code-line"><span class="token string">"Hello"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET key2
</span><span class="code-line"><span class="token string">"World"</span>
</span></code></pre>
<p>将多个键设置为多个值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="incrby"><a aria-hidden="true" tabindex="-1" href="#incrby"><span class="icon icon-link"></span></a>INCRBY</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">INCRBY key increment
</span></code></pre>
<h4 id="例子-43"><a aria-hidden="true" tabindex="-1" href="#例子-43"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"10"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> INCRBY mykey <span class="token number">5</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">15</span>
</span></code></pre>
<p>将键的整数值增加给定的数量</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="psetex"><a aria-hidden="true" tabindex="-1" href="#psetex"><span class="icon icon-link"></span></a>PSETEX</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">PSETEX key milliseconds value
</span></code></pre>
<h4 id="例子-44"><a aria-hidden="true" tabindex="-1" href="#例子-44"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PSETEX mykey <span class="token number">1000</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> PTTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1000</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>设置键的值和过期时间(以毫秒为单位)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="set"><a aria-hidden="true" tabindex="-1" href="#set"><span class="icon icon-link"></span></a>SET</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SET key value <span class="token punctuation">[</span>EX seconds<span class="token operator">|</span>PX milliseconds<span class="token operator">|</span>KEEPTTL<span class="token punctuation">]</span> <span class="token punctuation">[</span>NX<span class="token operator">|</span>XX<span class="token punctuation">]</span> 
</span><span class="code-line"><span class="token punctuation">[</span>GET<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-45"><a aria-hidden="true" tabindex="-1" href="#例子-45"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span><span class="code-line">redis<span class="token operator">></span> SET anotherkey <span class="token string">"will expire in a minute"</span> EX <span class="token number">60</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span></code></pre>
<p>设置键的字符串值,可以理解为创建、设置、重设的作用</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="setbit"><a aria-hidden="true" tabindex="-1" href="#setbit"><span class="icon icon-link"></span></a>SETBIT</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SETBIT key offset value
</span></code></pre>
<h4 id="例子-46"><a aria-hidden="true" tabindex="-1" href="#例子-46"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SETBIT mykey <span class="token number">7</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> SETBIT mykey <span class="token number">7</span> <span class="token number">0</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"<span class="token entity" title="\u0000">\u0000</span>"</span>
</span></code></pre>
<p>设置或清除存储在键中的字符串值中偏移量处的位</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="setex"><a aria-hidden="true" tabindex="-1" href="#setex"><span class="icon icon-link"></span></a>SETEX</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SETEX key seconds value
</span></code></pre>
<h4 id="例子-47"><a aria-hidden="true" tabindex="-1" href="#例子-47"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SETEX mykey <span class="token number">10</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> TTL mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>设置密钥的值和过期时间</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="setnx"><a aria-hidden="true" tabindex="-1" href="#setnx"><span class="icon icon-link"></span></a>SETNX</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SETNX key value
</span></code></pre>
<h4 id="例子-48"><a aria-hidden="true" tabindex="-1" href="#例子-48"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SETNX mykey <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SETNX mykey <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> GET mykey
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>设置键的值，仅当键不存在时</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="setrange"><a aria-hidden="true" tabindex="-1" href="#setrange"><span class="icon icon-link"></span></a>SETRANGE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SETRANGE key offset value
</span></code></pre>
<h4 id="例子-49"><a aria-hidden="true" tabindex="-1" href="#例子-49"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET key1 <span class="token string">"Hello World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> SETRANGE key1 <span class="token number">6</span> <span class="token string">"Redis"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">11</span>
</span><span class="code-line">redis<span class="token operator">></span> GET key1
</span><span class="code-line"><span class="token string">"Hello Redis"</span>
</span></code></pre>
<p>覆盖从指定偏移量开始的键处的字符串的一部分</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="strlen"><a aria-hidden="true" tabindex="-1" href="#strlen"><span class="icon icon-link"></span></a>STRLEN</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">STRLEN key
</span></code></pre>
<h4 id="例子-50"><a aria-hidden="true" tabindex="-1" href="#例子-50"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SET mykey <span class="token string">"Hello world"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> STRLEN mykey
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">11</span>
</span><span class="code-line">redis<span class="token operator">></span> STRLEN nonexisting
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>获取存储在键中的值的长度</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="stralgo"><a aria-hidden="true" tabindex="-1" href="#stralgo"><span class="icon icon-link"></span></a>STRALGO</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">STRALGO LCS algo-specific-argument <span class="token punctuation">[</span>algo-specific-argument 
</span><span class="code-line"><span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-51"><a aria-hidden="true" tabindex="-1" href="#例子-51"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> STRALGO LCS KEYS key1 key2 IDX
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"matches"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
</span><span class="code-line">         <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">         <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">8</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">         <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">         <span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"len"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span></code></pre>
<p>针对字符串运行算法(目前为 LCS)</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-集合类型设置"><a aria-hidden="true" tabindex="-1" href="#redis-集合类型设置"><span class="icon icon-link"></span></a>Redis 集合类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sadd"><a aria-hidden="true" tabindex="-1" href="#sadd"><span class="icon icon-link"></span></a>SADD</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SADD key member <span class="token punctuation">[</span>member <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-52"><a aria-hidden="true" tabindex="-1" href="#例子-52"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span></code></pre>
<p>将一个或多个成员添加到集合</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="scard"><a aria-hidden="true" tabindex="-1" href="#scard"><span class="icon icon-link"></span></a>SCARD</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SCARD key
</span></code></pre>
<h4 id="例子-53"><a aria-hidden="true" tabindex="-1" href="#例子-53"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SCARD myset
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>获取集合中的成员数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sdiff"><a aria-hidden="true" tabindex="-1" href="#sdiff"><span class="icon icon-link"></span></a>SDIFF</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SDIFF key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-54"><a aria-hidden="true" tabindex="-1" href="#例子-54"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SDIFF key1 key2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span></code></pre>
<p>减去多组</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sdiffstore"><a aria-hidden="true" tabindex="-1" href="#sdiffstore"><span class="icon icon-link"></span></a>SDIFFSTORE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SDIFFSTORE destination key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-55"><a aria-hidden="true" tabindex="-1" href="#例子-55"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SDIFFSTORE key key1 key2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS key
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span></code></pre>
<p>减去多个集合并将结果集合存储在一个键中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sinter"><a aria-hidden="true" tabindex="-1" href="#sinter"><span class="icon icon-link"></span></a>SINTER</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SINTER key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-56"><a aria-hidden="true" tabindex="-1" href="#例子-56"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SINTER key1 key2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span></code></pre>
<p>交叉多个集合</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sinterstore"><a aria-hidden="true" tabindex="-1" href="#sinterstore"><span class="icon icon-link"></span></a>SINTERSTORE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SINTERSTORE destination key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-57"><a aria-hidden="true" tabindex="-1" href="#例子-57"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SINTERSTORE key key1 key2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS key
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span></code></pre>
<p>将多个集合相交并将结果集合存储在一个键中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sismember"><a aria-hidden="true" tabindex="-1" href="#sismember"><span class="icon icon-link"></span></a>SISMEMBER</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SISMEMBER key member
</span></code></pre>
<h4 id="例子-58"><a aria-hidden="true" tabindex="-1" href="#例子-58"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SISMEMBER myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SISMEMBER myset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>确定给定值是否是集合的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="smismember"><a aria-hidden="true" tabindex="-1" href="#smismember"><span class="icon icon-link"></span></a>SMISMEMBER</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">SMISMEMBER key member <span class="token punctuation">[</span>member <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-59"><a aria-hidden="true" tabindex="-1" href="#例子-59"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> SMISMEMBER myset <span class="token string">"one"</span> <span class="token string">"notamember"</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>返回与集合的给定元素关联的成员资格</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="smembers"><a aria-hidden="true" tabindex="-1" href="#smembers"><span class="icon icon-link"></span></a>SMEMBERS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SMEMBERS key
</span></code></pre>
<h4 id="例子-60"><a aria-hidden="true" tabindex="-1" href="#例子-60"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span></code></pre>
<p>获取集合中的所有成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="smove"><a aria-hidden="true" tabindex="-1" href="#smove"><span class="icon icon-link"></span></a>SMOVE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SMOVE source destination member
</span></code></pre>
<h4 id="例子-61"><a aria-hidden="true" tabindex="-1" href="#例子-61"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myotherset <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SMOVE myset myotherset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myotherset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>将成员从一组移到另一组</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="spop"><a aria-hidden="true" tabindex="-1" href="#spop"><span class="icon icon-link"></span></a>SPOP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SPOP key [count]
</span></code></pre>
<h4 id="例子-62"><a aria-hidden="true" tabindex="-1" href="#例子-62"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SPOP myset
</span><span class="code-line"><span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"four"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"five"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SPOP myset <span class="token number">3</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"four"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"five"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span></code></pre>
<p>从集合中删除并返回一个或多个随机成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="srandmember"><a aria-hidden="true" tabindex="-1" href="#srandmember"><span class="icon icon-link"></span></a>SRANDMEMBER</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SRANDMEMBER key [count]
</span></code></pre>
<h4 id="例子-63"><a aria-hidden="true" tabindex="-1" href="#例子-63"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset one two three
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> SRANDMEMBER myset
</span><span class="code-line"><span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> SRANDMEMBER myset <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> SRANDMEMBER myset <span class="token parameter variable">-5</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span></code></pre>
<p>从一组中获取一个或多个随机成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="srem"><a aria-hidden="true" tabindex="-1" href="#srem"><span class="icon icon-link"></span></a>SREM</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SREM key member [member ...]
</span></code></pre>
<h4 id="例子-64"><a aria-hidden="true" tabindex="-1" href="#例子-64"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD myset <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SREM myset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SREM myset <span class="token string">"four"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS myset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>从集合中删除一个或多个成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sunion"><a aria-hidden="true" tabindex="-1" href="#sunion"><span class="icon icon-link"></span></a>SUNION</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SUNION key [key ...]
</span></code></pre>
<h4 id="例子-65"><a aria-hidden="true" tabindex="-1" href="#例子-65"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SUNION key1 key2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
</span></code></pre>
<p>添加多组</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="sunionstore"><a aria-hidden="true" tabindex="-1" href="#sunionstore"><span class="icon icon-link"></span></a>SUNIONSTORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">SUNIONSTORE destination key [key ...]
</span></code></pre>
<h4 id="例子-66"><a aria-hidden="true" tabindex="-1" href="#例子-66"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"a"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"b"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key1 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"c"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"d"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SADD key2 <span class="token string">"e"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> SUNIONSTORE key key1 key2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> SMEMBERS key
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
</span></code></pre>
<p>添加多个集合并将结果集合存储在一个键中</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-列表类型设置"><a aria-hidden="true" tabindex="-1" href="#redis-列表类型设置"><span class="icon icon-link"></span></a>Redis 列表类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助-3"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助-3"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">

















<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/brpoplpush">BRPOPLPUSH</a></td><td>从列表中弹出一个元素，将其推入另一个列表并返回；或阻塞直到有一个可用</td></tr><tr><td align="left"><a href="https://redis.io/commands/blmove">BLMOVE</a></td><td>从列表中弹出一个元素，将其推入另一个列表并返回；或阻塞直到有一个可用</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="blpop"><a aria-hidden="true" tabindex="-1" href="#blpop"><span class="icon icon-link"></span></a>BLPOP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">BLPOP key [key ...] timeout
</span></code></pre>
<h4 id="例子-67"><a aria-hidden="true" tabindex="-1" href="#例子-67"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> DEL list1 list2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH list1 a b c
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> BLPOP list1 list2 <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"list1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span></code></pre>
<p>删除并获取列表中的第一个元素，或者阻塞直到有一个元素可用</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="brpop"><a aria-hidden="true" tabindex="-1" href="#brpop"><span class="icon icon-link"></span></a>BRPOP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">BRPOP key [key ...] timeout
</span></code></pre>
<h4 id="例子-68"><a aria-hidden="true" tabindex="-1" href="#例子-68"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> DEL list1 list2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH list1 a b c
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> BRPOP list1 list2 <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"list1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span></code></pre>
<p>删除并获取列表中的最后一个元素，或者阻塞直到有一个可用</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lindex"><a aria-hidden="true" tabindex="-1" href="#lindex"><span class="icon icon-link"></span></a>LINDEX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LINDEX key index
</span></code></pre>
<h4 id="例子-69"><a aria-hidden="true" tabindex="-1" href="#例子-69"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LINDEX mylist <span class="token number">0</span>
</span><span class="code-line"><span class="token string">"Hello"</span>
</span><span class="code-line">redis<span class="token operator">></span> LINDEX mylist <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token string">"World"</span>
</span><span class="code-line">redis<span class="token operator">></span> LINDEX mylist <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>通过索引从列表中获取元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="linsert"><a aria-hidden="true" tabindex="-1" href="#linsert"><span class="icon icon-link"></span></a>LINSERT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LINSERT key BEFORE|AFTER pivot element
</span></code></pre>
<h4 id="例子-70"><a aria-hidden="true" tabindex="-1" href="#例子-70"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LINSERT mylist BEFORE <span class="token string">"World"</span> <span class="token string">"There"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"There"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span></code></pre>
<p>在列表中的另一个元素之前或之后插入一个元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="llen"><a aria-hidden="true" tabindex="-1" href="#llen"><span class="icon icon-link"></span></a>LLEN</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LLEN key
</span></code></pre>
<h4 id="例子-71"><a aria-hidden="true" tabindex="-1" href="#例子-71"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LLEN mylist
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>获取列表的长度</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lpop"><a aria-hidden="true" tabindex="-1" href="#lpop"><span class="icon icon-link"></span></a>LPOP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LPOP key [count]
</span></code></pre>
<h4 id="例子-72"><a aria-hidden="true" tabindex="-1" href="#例子-72"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LPOP mylist
</span><span class="code-line"><span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>删除并获取列表中的第一个元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lpos"><a aria-hidden="true" tabindex="-1" href="#lpos"><span class="icon icon-link"></span></a>LPOS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LPOS key element [RANK rank] [COUNT num-matches] [MAXLEN len]
</span></code></pre>
<h4 id="例子-73"><a aria-hidden="true" tabindex="-1" href="#例子-73"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist a b c d <span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span> <span class="token number">4</span> <span class="token number">3</span> <span class="token number">3</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">11</span>
</span><span class="code-line">redis<span class="token operator">></span> LPOS mylist <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span><span class="code-line">redis<span class="token operator">></span> LPOS mylist <span class="token number">3</span> COUNT <span class="token number">0</span> RANK <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">8</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">9</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span></code></pre>
<p>返回列表中匹配元素的索引</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lpush"><a aria-hidden="true" tabindex="-1" href="#lpush"><span class="icon icon-link"></span></a>LPUSH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LPUSH key element [element ...]
</span></code></pre>
<h4 id="例子-74"><a aria-hidden="true" tabindex="-1" href="#例子-74"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"world"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"world"</span>
</span></code></pre>
<p>将一个或多个元素添加到列表中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lpushx"><a aria-hidden="true" tabindex="-1" href="#lpushx"><span class="icon icon-link"></span></a>LPUSHX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LPUSHX key element [element ...]
</span></code></pre>
<h4 id="例子-75"><a aria-hidden="true" tabindex="-1" href="#例子-75"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> LPUSH mylist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSHX mylist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LPUSHX myotherlist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE myotherlist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>仅当列表存在时才将元素添加到列表中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lrange"><a aria-hidden="true" tabindex="-1" href="#lrange"><span class="icon icon-link"></span></a>LRANGE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LRANGE key start stop
</span></code></pre>
<h4 id="例子-76"><a aria-hidden="true" tabindex="-1" href="#例子-76"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token parameter variable">-3</span> <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token parameter variable">-100</span> <span class="token number">100</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">5</span> <span class="token number">10</span>
</span><span class="code-line"><span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>从列表中获取一系列元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lrem"><a aria-hidden="true" tabindex="-1" href="#lrem"><span class="icon icon-link"></span></a>LREM</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LREM key count element
</span></code></pre>
<h4 id="例子-77"><a aria-hidden="true" tabindex="-1" href="#例子-77"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"foo"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
</span><span class="code-line">redis<span class="token operator">></span> LREM mylist <span class="token parameter variable">-2</span> <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"foo"</span>
</span></code></pre>
<p>从列表中删除元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lset"><a aria-hidden="true" tabindex="-1" href="#lset"><span class="icon icon-link"></span></a>LSET</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LSET key index element
</span></code></pre>
<h4 id="例子-78"><a aria-hidden="true" tabindex="-1" href="#例子-78"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LSET mylist <span class="token number">0</span> <span class="token string">"four"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> LSET mylist <span class="token parameter variable">-2</span> <span class="token string">"five"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"four"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"five"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>通过索引设置列表中元素的值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="ltrim"><a aria-hidden="true" tabindex="-1" href="#ltrim"><span class="icon icon-link"></span></a>LTRIM</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LTRIM key start stop
</span></code></pre>
<h4 id="例子-79"><a aria-hidden="true" tabindex="-1" href="#例子-79"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LTRIM mylist <span class="token number">1</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>将列表修剪到指定范围</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="rpop"><a aria-hidden="true" tabindex="-1" href="#rpop"><span class="icon icon-link"></span></a>RPOP</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RPOP key [count]
</span></code></pre>
<h4 id="例子-80"><a aria-hidden="true" tabindex="-1" href="#例子-80"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> RPOP mylist
</span><span class="code-line"><span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span></code></pre>
<p>删除并获取列表中的最后一个元素</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="rpoplpush"><a aria-hidden="true" tabindex="-1" href="#rpoplpush"><span class="icon icon-link"></span></a>RPOPLPUSH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RPOPLPUSH source destination
</span></code></pre>
<h4 id="例子-81"><a aria-hidden="true" tabindex="-1" href="#例子-81"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> RPOPLPUSH mylist myotherlist
</span><span class="code-line"><span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE myotherlist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>删除列表中的最后一个元素，将其添加到另一个列表中并返回</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="lmove"><a aria-hidden="true" tabindex="-1" href="#lmove"><span class="icon icon-link"></span></a>LMOVE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">LMOVE source destination LEFT|RIGHT LEFT|RIGHT
</span></code></pre>
<h4 id="例子-82"><a aria-hidden="true" tabindex="-1" href="#例子-82"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> LMOVE mylist myotherlist RIGHT LEFT
</span><span class="code-line"><span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> LMOVE mylist myotherlist LEFT RIGHT
</span><span class="code-line"><span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE myotherlist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span></code></pre>
<p>从列表中弹出一个元素，将其推入另一个列表并返回</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="rpush"><a aria-hidden="true" tabindex="-1" href="#rpush"><span class="icon icon-link"></span></a>RPUSH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RPUSH key element [element ...]
</span></code></pre>
<h4 id="例子-83"><a aria-hidden="true" tabindex="-1" href="#例子-83"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"world"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"world"</span>
</span></code></pre>
<p>将一个或多个元素附加到列表</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="rpushx"><a aria-hidden="true" tabindex="-1" href="#rpushx"><span class="icon icon-link"></span></a>RPUSHX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">RPUSHX key element [element ...]
</span></code></pre>
<h4 id="例子-84"><a aria-hidden="true" tabindex="-1" href="#例子-84"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> RPUSH mylist <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSHX mylist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> RPUSHX myotherlist <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE mylist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span><span class="code-line">redis<span class="token operator">></span> LRANGE myotherlist <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>仅当列表存在时才将元素附加到列表</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-哈希类型设置"><a aria-hidden="true" tabindex="-1" href="#redis-哈希类型设置"><span class="icon icon-link"></span></a>Redis 哈希类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hdel"><a aria-hidden="true" tabindex="-1" href="#hdel"><span class="icon icon-link"></span></a>HDEL</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HDEL key field [field ...]
</span></code></pre>
<h4 id="例子-85"><a aria-hidden="true" tabindex="-1" href="#例子-85"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"foo"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HDEL myhash field1
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HDEL myhash field2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>删除一个或多个哈希字段</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hexists"><a aria-hidden="true" tabindex="-1" href="#hexists"><span class="icon icon-link"></span></a>HEXISTS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HEXISTS key field
</span></code></pre>
<h4 id="例子-86"><a aria-hidden="true" tabindex="-1" href="#例子-86"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"foo"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HEXISTS myhash field1
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HEXISTS myhash field2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span></code></pre>
<p>判断哈希字段是否存在</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hget"><a aria-hidden="true" tabindex="-1" href="#hget"><span class="icon icon-link"></span></a>HGET</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HGET key field
</span></code></pre>
<h4 id="例子-87"><a aria-hidden="true" tabindex="-1" href="#例子-87"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"foo"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field1
</span><span class="code-line"><span class="token string">"foo"</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field2
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>获取哈希字段的值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hgetall"><a aria-hidden="true" tabindex="-1" href="#hgetall"><span class="icon icon-link"></span></a>HGETALL</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HGETALL key
</span></code></pre>
<h4 id="例子-88"><a aria-hidden="true" tabindex="-1" href="#例子-88"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET myhash field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HGETALL myhash
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"field1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"field2"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span></code></pre>
<p>获取哈希中的所有字段和值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hincrby"><a aria-hidden="true" tabindex="-1" href="#hincrby"><span class="icon icon-link"></span></a>HINCRBY</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HINCRBY key field increment
</span></code></pre>
<h4 id="例子-89"><a aria-hidden="true" tabindex="-1" href="#例子-89"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field <span class="token number">5</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBY myhash field <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBY myhash field <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBY myhash field <span class="token parameter variable">-10</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token parameter variable">-5</span>
</span></code></pre>
<p>将哈希字段的整数值增加给定的数字</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hincrbyfloat"><a aria-hidden="true" tabindex="-1" href="#hincrbyfloat"><span class="icon icon-link"></span></a>HINCRBYFLOAT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HINCRBYFLOAT key field increment
</span></code></pre>
<h4 id="例子-90"><a aria-hidden="true" tabindex="-1" href="#例子-90"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET mykey field <span class="token number">10.50</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBYFLOAT mykey field <span class="token number">0.1</span>
</span><span class="code-line"><span class="token string">"10.6"</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBYFLOAT mykey field <span class="token parameter variable">-5</span>
</span><span class="code-line"><span class="token string">"5.6"</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET mykey field <span class="token number">5</span>.0e3
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> HINCRBYFLOAT mykey field <span class="token number">2</span>.0e2
</span><span class="code-line"><span class="token string">"5200"</span>
</span></code></pre>
<p>将哈希字段的浮点值增加给定的数量</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hkeys"><a aria-hidden="true" tabindex="-1" href="#hkeys"><span class="icon icon-link"></span></a>HKEYS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HKEYS key
</span></code></pre>
<h4 id="例子-91"><a aria-hidden="true" tabindex="-1" href="#例子-91"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET myhash field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HKEYS myhash
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"field1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"field2"</span>
</span></code></pre>
<p>获取哈希中的所有字段</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hlen"><a aria-hidden="true" tabindex="-1" href="#hlen"><span class="icon icon-link"></span></a>HLEN</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HLEN key
</span></code></pre>
<h4 id="例子-92"><a aria-hidden="true" tabindex="-1" href="#例子-92"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET myhash field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HLEN myhash
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>获取哈希中的字段数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hmget"><a aria-hidden="true" tabindex="-1" href="#hmget"><span class="icon icon-link"></span></a>HMGET</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HMGET key field [field ...]
</span></code></pre>
<h4 id="例子-93"><a aria-hidden="true" tabindex="-1" href="#例子-93"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET myhash field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HMGET myhash field1 field2 nofield
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>获取所有给定哈希字段的值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hmset"><a aria-hidden="true" tabindex="-1" href="#hmset"><span class="icon icon-link"></span></a>HMSET</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HMSET key field value [field value ...]
</span></code></pre>
<h4 id="例子-94"><a aria-hidden="true" tabindex="-1" href="#例子-94"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HMSET myhash field1 <span class="token string">"Hello"</span> field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field1
</span><span class="code-line"><span class="token string">"Hello"</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field2
</span><span class="code-line"><span class="token string">"World"</span>
</span></code></pre>
<p>将多个哈希字段设置为多个值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hset"><a aria-hidden="true" tabindex="-1" href="#hset"><span class="icon icon-link"></span></a>HSET</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HSET key field value [field value ...]
</span></code></pre>
<h4 id="例子-95"><a aria-hidden="true" tabindex="-1" href="#例子-95"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field1
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>设置哈希字段的字符串值</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hsetnx"><a aria-hidden="true" tabindex="-1" href="#hsetnx"><span class="icon icon-link"></span></a>HSETNX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HSETNX key field value
</span></code></pre>
<h4 id="例子-96"><a aria-hidden="true" tabindex="-1" href="#例子-96"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSETNX myhash field <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSETNX myhash field <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> HGET myhash field
</span><span class="code-line"><span class="token string">"Hello"</span>
</span></code></pre>
<p>设置哈希字段的值，仅当该字段不存在时</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hstrlen"><a aria-hidden="true" tabindex="-1" href="#hstrlen"><span class="icon icon-link"></span></a>HSTRLEN</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HSTRLEN key field
</span></code></pre>
<h4 id="例子-97"><a aria-hidden="true" tabindex="-1" href="#例子-97"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HMSET myhash f1 HelloWorld f2 <span class="token number">99</span> f3 <span class="token parameter variable">-256</span>
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> HSTRLEN myhash f1
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">10</span>
</span><span class="code-line">redis<span class="token operator">></span> HSTRLEN myhash f2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> HSTRLEN myhash f3
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">4</span>
</span></code></pre>
<p>获取哈希字段值的长度</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="hvals"><a aria-hidden="true" tabindex="-1" href="#hvals"><span class="icon icon-link"></span></a>HVALS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">HVALS key
</span></code></pre>
<h4 id="例子-98"><a aria-hidden="true" tabindex="-1" href="#例子-98"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> HSET myhash field1 <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HSET myhash field2 <span class="token string">"World"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> HVALS myhash
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Hello"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"World"</span>
</span></code></pre>
<p>获取哈希中的所有值</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis-排序集类型设置"><a aria-hidden="true" tabindex="-1" href="#redis-排序集类型设置"><span class="icon icon-link"></span></a>Redis 排序集类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bzpopmin"><a aria-hidden="true" tabindex="-1" href="#bzpopmin"><span class="icon icon-link"></span></a>BZPOPMIN</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">BZPOPMIN key [key ...] timeout
</span></code></pre>
<h4 id="例子-99"><a aria-hidden="true" tabindex="-1" href="#例子-99"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> DEL zset1 zset2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">0</span> a <span class="token number">1</span> b <span class="token number">2</span> c
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> BZPOPMIN zset1 zset2 <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"zset1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"0"</span>
</span></code></pre>
<p>从一个或多个排序集合中删除并返回得分最低的成员，或者阻塞直到一个可用</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="bzpopmax"><a aria-hidden="true" tabindex="-1" href="#bzpopmax"><span class="icon icon-link"></span></a>BZPOPMAX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">BZPOPMAX key [key ...] timeout
</span></code></pre>
<h4 id="例子-100"><a aria-hidden="true" tabindex="-1" href="#例子-100"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> DEL zset1 zset2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">0</span> a <span class="token number">1</span> b <span class="token number">2</span> c
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> BZPOPMAX zset1 zset2 <span class="token number">0</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"zset1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span></code></pre>
<p>从一个或多个排序集合中删除并返回得分最高的成员，或者阻塞直到一个可用</p>
</div></div></div><div class="wrap h3body-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="zadd"><a aria-hidden="true" tabindex="-1" href="#zadd"><span class="icon icon-link"></span></a>ZADD</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre><code class="code-highlight"><span class="code-line">ZADD key [NX|XX] [GT|LT] [CH] [INCR] score member [score 
</span><span class="code-line">member ...]
</span></code></pre>
<h4 id="例子-101"><a aria-hidden="true" tabindex="-1" href="#例子-101"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"uno"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span> <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"1"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"uno"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"1"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>将一个或多个成员添加到有序集合中，或者更新其分数(如果它已经存在)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zcard"><a aria-hidden="true" tabindex="-1" href="#zcard"><span class="icon icon-link"></span></a>ZCARD</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZCARD key
</span></code></pre>
<h4 id="例子-102"><a aria-hidden="true" tabindex="-1" href="#例子-102"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZCARD myzset
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>获取有序集合中的成员数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zscore"><a aria-hidden="true" tabindex="-1" href="#zscore"><span class="icon icon-link"></span></a>ZSCORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZSCORE key member
</span></code></pre>
<h4 id="例子-103"><a aria-hidden="true" tabindex="-1" href="#例子-103"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZSCORE myzset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token string">"1"</span>
</span></code></pre>
<p>获取与排序集中给定成员关联的分数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zcount"><a aria-hidden="true" tabindex="-1" href="#zcount"><span class="icon icon-link"></span></a>ZCOUNT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZCOUNT key min max
</span></code></pre>
<h4 id="例子-104"><a aria-hidden="true" tabindex="-1" href="#例子-104"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZCOUNT myzset <span class="token parameter variable">-inf</span> +inf
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> ZCOUNT myzset <span class="token punctuation">(</span><span class="token number">1</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span></code></pre>
<p>计算得分在给定值内的排序集中的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zdiff"><a aria-hidden="true" tabindex="-1" href="#zdiff"><span class="icon icon-link"></span></a>ZDIFF</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZDIFF numkeys key [key ...] [WITHSCORES]
</span></code></pre>
<h4 id="例子-105"><a aria-hidden="true" tabindex="-1" href="#例子-105"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZDIFF <span class="token number">2</span> zset1 zset2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZDIFF <span class="token number">2</span> zset1 zset2 WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>减去多个排序集</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zdiffstore"><a aria-hidden="true" tabindex="-1" href="#zdiffstore"><span class="icon icon-link"></span></a>ZDIFFSTORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZDIFFSTORE destination numkeys key [key ...]
</span></code></pre>
<h4 id="例子-106"><a aria-hidden="true" tabindex="-1" href="#例子-106"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZDIFFSTORE out <span class="token number">2</span> zset1 zset2
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE out <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>减去多个排序集并将生成的排序集存储在新键中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zincrby"><a aria-hidden="true" tabindex="-1" href="#zincrby"><span class="icon icon-link"></span></a>ZINCRBY</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZINCRBY key increment member
</span></code></pre>
<h4 id="例子-107"><a aria-hidden="true" tabindex="-1" href="#例子-107"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZINCRBY myzset <span class="token number">2</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token string">"3"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>增加排序集中成员的分数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zinter"><a aria-hidden="true" tabindex="-1" href="#zinter"><span class="icon icon-link"></span></a>ZINTER</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZINTER numkeys key [key ...] [WEIGHTS weight [weight ...]] 
</span><span class="code-line">[AGGREGATE SUM|MIN|MAX] [WITHSCORES]
</span></code></pre>
<h4 id="例子-108"><a aria-hidden="true" tabindex="-1" href="#例子-108"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZINTER <span class="token number">2</span> zset1 zset2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZINTER <span class="token number">2</span> zset1 zset2 WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"4"</span>
</span></code></pre>
<p>与多个排序集相交</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zinterstore"><a aria-hidden="true" tabindex="-1" href="#zinterstore"><span class="icon icon-link"></span></a>ZINTERSTORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZINTERSTORE destination numkeys key [key ...] [WEIGHTS weight 
</span><span class="code-line">[weight ...]] [AGGREGATE SUM|MIN|MAX]
</span></code></pre>
<h4 id="例子-109"><a aria-hidden="true" tabindex="-1" href="#例子-109"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZINTERSTORE out <span class="token number">2</span> zset1 zset2 WEIGHTS <span class="token number">2</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE out <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"5"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"10"</span>
</span></code></pre>
<p>将多个排序集相交并将生成的排序集存储在新键中</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zlexcount"><a aria-hidden="true" tabindex="-1" href="#zlexcount"><span class="icon icon-link"></span></a>ZLEXCOUNT</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZLEXCOUNT key min max
</span></code></pre>
<h4 id="例子-110"><a aria-hidden="true" tabindex="-1" href="#例子-110"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> a <span class="token number">0</span> b <span class="token number">0</span> c <span class="token number">0</span> d <span class="token number">0</span> e
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> f <span class="token number">0</span> g
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZLEXCOUNT myzset - +
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span><span class="code-line">redis<span class="token operator">></span> ZLEXCOUNT myzset <span class="token punctuation">[</span>b <span class="token punctuation">[</span>f
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span></code></pre>
<p>计算给定词典范围之间的有序集合中的成员数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zpopmax"><a aria-hidden="true" tabindex="-1" href="#zpopmax"><span class="icon icon-link"></span></a>ZPOPMAX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZPOPMAX key [count]
</span></code></pre>
<h4 id="例子-111"><a aria-hidden="true" tabindex="-1" href="#例子-111"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZPOPMAX myzset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>删除并返回排序集中得分最高的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zpopmin"><a aria-hidden="true" tabindex="-1" href="#zpopmin"><span class="icon icon-link"></span></a>ZPOPMIN</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZPOPMIN key [count]
</span></code></pre>
<h4 id="例子-112"><a aria-hidden="true" tabindex="-1" href="#例子-112"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZPOPMIN myzset
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"1"</span>
</span></code></pre>
<p>删除并返回排序集中得分最低的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrange"><a aria-hidden="true" tabindex="-1" href="#zrange"><span class="icon icon-link"></span></a>ZRANGE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZRANGE key start stop [WITHSCORES]
</span></code></pre>
<h4 id="例子-113"><a aria-hidden="true" tabindex="-1" href="#例子-113"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">2</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token parameter variable">-2</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span></code></pre>
<p>按索引返回排序集中的一系列成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrangebylex"><a aria-hidden="true" tabindex="-1" href="#zrangebylex"><span class="icon icon-link"></span></a>ZRANGEBYLEX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZRANGEBYLEX key min max [LIMIT offset count]
</span></code></pre>
<h4 id="例子-114"><a aria-hidden="true" tabindex="-1" href="#例子-114"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> a <span class="token number">0</span> b <span class="token number">0</span> c <span class="token number">0</span> d <span class="token number">0</span> e <span class="token number">0</span> f <span class="token number">0</span> g
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYLEX myzset - <span class="token punctuation">[</span>c
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYLEX myzset - <span class="token punctuation">(</span>c
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYLEX myzset <span class="token punctuation">[</span>aaa <span class="token punctuation">(</span>g
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"f"</span>
</span></code></pre>
<p>按词典顺序返回排序集中的一系列成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrevrangebylex"><a aria-hidden="true" tabindex="-1" href="#zrevrangebylex"><span class="icon icon-link"></span></a>ZREVRANGEBYLEX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREVRANGEBYLEX key max min [LIMIT offset count]
</span></code></pre>
<h4 id="例子-115"><a aria-hidden="true" tabindex="-1" href="#例子-115"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> a <span class="token number">0</span> b <span class="token number">0</span> c <span class="token number">0</span> d <span class="token number">0</span> e <span class="token number">0</span> f <span class="token number">0</span> g
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYLEX myzset <span class="token punctuation">[</span>c -
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYLEX myzset <span class="token punctuation">(</span>c -
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"a"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYLEX myzset <span class="token punctuation">(</span>g <span class="token punctuation">[</span>aaa
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"f"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span></code></pre>
<p>返回排序集中的一系列成员，按字典范围，从高到低的字符串排序。</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrangebyscore"><a aria-hidden="true" tabindex="-1" href="#zrangebyscore"><span class="icon icon-link"></span></a>ZRANGEBYSCORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZRANGEBYSCORE key min max [WITHSCORES] [LIMIT offset count]
</span></code></pre>
<h4 id="例子-116"><a aria-hidden="true" tabindex="-1" href="#例子-116"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYSCORE myzset <span class="token parameter variable">-inf</span> +inf
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYSCORE myzset <span class="token number">1</span> <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYSCORE myzset <span class="token punctuation">(</span><span class="token number">1</span> <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGEBYSCORE myzset <span class="token punctuation">(</span><span class="token number">1</span> <span class="token punctuation">(</span><span class="token number">2</span>
</span><span class="code-line"><span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>按分数返回排序集中的一系列成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrank"><a aria-hidden="true" tabindex="-1" href="#zrank"><span class="icon icon-link"></span></a>ZRANK</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZRANK key member
</span></code></pre>
<h4 id="例子-117"><a aria-hidden="true" tabindex="-1" href="#例子-117"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANK myzset <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANK myzset <span class="token string">"four"</span>
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>确定有序集合中成员的索引</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrem"><a aria-hidden="true" tabindex="-1" href="#zrem"><span class="icon icon-link"></span></a>ZREM</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREM key member [member ...]
</span></code></pre>
<h4 id="例子-118"><a aria-hidden="true" tabindex="-1" href="#例子-118"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREM myzset <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"1"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>从有序集合中移除一个或多个成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zremrangebylex"><a aria-hidden="true" tabindex="-1" href="#zremrangebylex"><span class="icon icon-link"></span></a>ZREMRANGEBYLEX</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREMRANGEBYLEX key min max
</span></code></pre>
<h4 id="例子-119"><a aria-hidden="true" tabindex="-1" href="#例子-119"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> aaaa <span class="token number">0</span> b <span class="token number">0</span> c <span class="token number">0</span> d <span class="token number">0</span> e
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">0</span> foo <span class="token number">0</span> zap <span class="token number">0</span> <span class="token function">zip</span> <span class="token number">0</span> ALPHA <span class="token number">0</span> alpha
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"ALPHA"</span>
</span><span class="code-line"> <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"aaaa"</span>
</span><span class="code-line"> <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"alpha"</span>
</span><span class="code-line"> <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"b"</span>
</span><span class="code-line"> <span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"c"</span>
</span><span class="code-line"> <span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"d"</span>
</span><span class="code-line"> <span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"e"</span>
</span><span class="code-line"> <span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"foo"</span>
</span><span class="code-line"> <span class="token number">9</span><span class="token punctuation">)</span> <span class="token string">"zap"</span>
</span><span class="code-line"><span class="token number">10</span><span class="token punctuation">)</span> <span class="token string">"zip"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREMRANGEBYLEX myzset <span class="token punctuation">[</span>alpha <span class="token punctuation">[</span>omega
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"ALPHA"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"aaaa"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"zap"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"zip"</span>
</span></code></pre>
<p>删除给定词典范围之间的排序集中的所有成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zremrangebyrank"><a aria-hidden="true" tabindex="-1" href="#zremrangebyrank"><span class="icon icon-link"></span></a>ZREMRANGEBYRANK</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREMRANGEBYRANK key start stop
</span></code></pre>
<h4 id="例子-120"><a aria-hidden="true" tabindex="-1" href="#例子-120"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREMRANGEBYRANK myzset <span class="token number">0</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>删除给定索引内排序集中的所有成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zremrangebyscore"><a aria-hidden="true" tabindex="-1" href="#zremrangebyscore"><span class="icon icon-link"></span></a>ZREMRANGEBYSCORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREMRANGEBYSCORE key min max
</span></code></pre>
<h4 id="例子-121"><a aria-hidden="true" tabindex="-1" href="#例子-121"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREMRANGEBYSCORE myzset <span class="token parameter variable">-inf</span> <span class="token punctuation">(</span><span class="token number">2</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span></code></pre>
<p>删除给定分数内排序集中的所有成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrevrange"><a aria-hidden="true" tabindex="-1" href="#zrevrange"><span class="icon icon-link"></span></a>ZREVRANGE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREVRANGE key start stop [WITHSCORES]
</span></code></pre>
<h4 id="例子-122"><a aria-hidden="true" tabindex="-1" href="#例子-122"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGE myzset <span class="token number">0</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGE myzset <span class="token number">2</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGE myzset <span class="token parameter variable">-2</span> <span class="token parameter variable">-1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span></code></pre>
<p>按索引返回排序集中的一系列成员，分数从高到低排序</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrevrangebyscore"><a aria-hidden="true" tabindex="-1" href="#zrevrangebyscore"><span class="icon icon-link"></span></a>ZREVRANGEBYSCORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREVRANGEBYSCORE key max min [WITHSCORES] [LIMIT offset count]
</span></code></pre>
<h4 id="例子-123"><a aria-hidden="true" tabindex="-1" href="#例子-123"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYSCORE myzset +inf <span class="token parameter variable">-inf</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYSCORE myzset <span class="token number">2</span> <span class="token number">1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYSCORE myzset <span class="token number">2</span> <span class="token punctuation">(</span><span class="token number">1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANGEBYSCORE myzset <span class="token punctuation">(</span><span class="token number">2</span> <span class="token punctuation">(</span><span class="token number">1</span>
</span><span class="code-line"><span class="token punctuation">(</span>empty list or <span class="token builtin class-name">set</span><span class="token punctuation">)</span>
</span></code></pre>
<p>按分数返回排序集中的一系列成员，分数从高到低排序</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zrevrank"><a aria-hidden="true" tabindex="-1" href="#zrevrank"><span class="icon icon-link"></span></a>ZREVRANK</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZREVRANK key member
</span></code></pre>
<h4 id="例子-124"><a aria-hidden="true" tabindex="-1" href="#例子-124"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANK myzset <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> ZREVRANK myzset <span class="token string">"four"</span>
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>确定一个成员在有序集合中的索引，分数从高到低排序</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zunion"><a aria-hidden="true" tabindex="-1" href="#zunion"><span class="icon icon-link"></span></a>ZUNION</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZUNION numkeys key [key ...] [WEIGHTS weight [weight ...]] 
</span><span class="code-line">[AGGREGATE SUM|MIN|MAX] [WITHSCORES]
</span></code></pre>
<h4 id="例子-125"><a aria-hidden="true" tabindex="-1" href="#例子-125"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZUNION <span class="token number">2</span> zset1 zset2
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line">redis<span class="token operator">></span> ZUNION <span class="token number">2</span> zset1 zset2 WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"3"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"4"</span>
</span></code></pre>
<p>添加多个排序集</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zmscore"><a aria-hidden="true" tabindex="-1" href="#zmscore"><span class="icon icon-link"></span></a>ZMSCORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZMSCORE key member [member ...]
</span></code></pre>
<h4 id="例子-126"><a aria-hidden="true" tabindex="-1" href="#例子-126"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD myzset <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZMSCORE myzset <span class="token string">"one"</span> <span class="token string">"two"</span> <span class="token string">"nofield"</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"2"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>获取与排序集中给定成员关联的分数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="zunionstore"><a aria-hidden="true" tabindex="-1" href="#zunionstore"><span class="icon icon-link"></span></a>ZUNIONSTORE</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">ZUNIONSTORE destination numkeys key [key ...] [WEIGHTS weight 
</span><span class="code-line">[weight ...]] [AGGREGATE SUM|MIN|MAX]
</span></code></pre>
<h4 id="例子-127"><a aria-hidden="true" tabindex="-1" href="#例子-127"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset1 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">1</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">2</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZADD zset2 <span class="token number">3</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> ZUNIONSTORE out <span class="token number">2</span> zset1 zset2 WEIGHTS <span class="token number">2</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> ZRANGE out <span class="token number">0</span> <span class="token parameter variable">-1</span> WITHSCORES
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"one"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"5"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"three"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"9"</span>
</span><span class="code-line"><span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"two"</span>
</span><span class="code-line"><span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"10"</span>
</span></code></pre>
<p>添加多个排序集并将生成的排序集存储在新键中</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis地图坐标集类型设置"><a aria-hidden="true" tabindex="-1" href="#redis地图坐标集类型设置"><span class="icon icon-link"></span></a>Redis地图坐标集类型设置</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="geoadd"><a aria-hidden="true" tabindex="-1" href="#geoadd"><span class="icon icon-link"></span></a>GEOADD</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEOADD key longitude latitude member [longitude latitude member ...]
</span></code></pre>
<h4 id="例子-128"><a aria-hidden="true" tabindex="-1" href="#例子-128"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEODIST Sicily Palermo Catania
</span><span class="code-line"><span class="token string">"166274.1516"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUS Sicily <span class="token number">15</span> <span class="token number">37</span> <span class="token number">100</span> km
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUS Sicily <span class="token number">15</span> <span class="token number">37</span> <span class="token number">200</span> km
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span></code></pre>
<p>在使用排序集表示的地理空间索引中添加一个或多个地理空间项</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="geohash"><a aria-hidden="true" tabindex="-1" href="#geohash"><span class="icon icon-link"></span></a>GEOHASH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEOHASH key member [member ...]
</span></code></pre>
<h4 id="例子-129"><a aria-hidden="true" tabindex="-1" href="#例子-129"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOHASH Sicily Palermo Catania
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"sqc8b49rny0"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"sqdtr74hyu0"</span>
</span></code></pre>
<p>将地理空间索引的成员作为标准 geohash 字符串返回</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="geopos"><a aria-hidden="true" tabindex="-1" href="#geopos"><span class="icon icon-link"></span></a>GEOPOS</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEOPOS key member [member ...]
</span></code></pre>
<h4 id="例子-130"><a aria-hidden="true" tabindex="-1" href="#例子-130"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOPOS Sicily Palermo Catania NonExisting
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"13.36138933897018433"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"38.11555639549629859"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"15.08726745843887329"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"37.50266842333162032"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>返回地理空间索引成员的经度和纬度</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="geodist"><a aria-hidden="true" tabindex="-1" href="#geodist"><span class="icon icon-link"></span></a>GEODIST</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEODIST key member1 member2 [m|km|ft|mi]
</span></code></pre>
<h4 id="例子-131"><a aria-hidden="true" tabindex="-1" href="#例子-131"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEODIST Sicily Palermo Catania
</span><span class="code-line"><span class="token string">"166274.1516"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEODIST Sicily Palermo Catania km
</span><span class="code-line"><span class="token string">"166.2742"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEODIST Sicily Palermo Catania mi
</span><span class="code-line"><span class="token string">"103.3182"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEODIST Sicily Foo Bar
</span><span class="code-line"><span class="token punctuation">(</span>nil<span class="token punctuation">)</span>
</span></code></pre>
<p>返回地理空间索引的两个成员之间的距离</p>
</div></div></div><div class="wrap h3body-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="georadius"><a aria-hidden="true" tabindex="-1" href="#georadius"><span class="icon icon-link"></span></a>GEORADIUS</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->
<pre><code class="code-highlight"><span class="code-line">GEORADIUS key longitude latitude radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT 
</span><span class="code-line">count] [ASC|DESC] [STORE key] [STOREDIST key]
</span></code></pre>
<h4 id="例子-132"><a aria-hidden="true" tabindex="-1" href="#例子-132"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUS Sicily <span class="token number">15</span> <span class="token number">37</span> <span class="token number">200</span> km WITHDIST
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"190.4424"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"56.4413"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUS Sicily <span class="token number">15</span> <span class="token number">37</span> <span class="token number">200</span> km WITHCOORD
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"13.36138933897018433"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"38.11555639549629859"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"15.08726745843887329"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"37.50266842333162032"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUS Sicily <span class="token number">15</span> <span class="token number">37</span> <span class="token number">200</span> km WITHDIST WITHCOORD
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"190.4424"</span>
</span><span class="code-line">   <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"13.36138933897018433"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"38.11555639549629859"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"56.4413"</span>
</span><span class="code-line">   <span class="token number">3</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"15.08726745843887329"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"37.50266842333162032"</span>
</span></code></pre>
<p>查询表示地理空间索引的排序集，以获取与某个点的给定最大距离匹配的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="georadiusbymember"><a aria-hidden="true" tabindex="-1" href="#georadiusbymember"><span class="icon icon-link"></span></a>GEORADIUSBYMEMBER</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEORADIUSBYMEMBER key member radius m|km|ft|mi [WITHCOORD] [WITHDIST] [WITHHASH] [COUNT count] 
</span><span class="code-line">[ASC|DESC] [STORE key] [STOREDIST key]
</span></code></pre>
<h4 id="例子-133"><a aria-hidden="true" tabindex="-1" href="#例子-133"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.583333</span> <span class="token number">37.316667</span> <span class="token string">"Agrigento"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEORADIUSBYMEMBER Sicily Agrigento <span class="token number">100</span> km
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Agrigento"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span></code></pre>
<p>查询表示地理空间索引的排序集，以获取与成员的给定最大距离相匹配的成员</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="geosearch"><a aria-hidden="true" tabindex="-1" href="#geosearch"><span class="icon icon-link"></span></a>GEOSEARCH</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">GEOSEARCH key [FROMMEMBER member] [FROMLONLAT longitude latitude] [BYRADIUS radius m|km|ft|mi] 
</span><span class="code-line">[BYBOX width height m|km|ft|mi] [ASC|DESC] [COUNT count] [WITHCOORD] [WITHDIST] [WITHHASH]
</span></code></pre>
<h4 id="例子-134"><a aria-hidden="true" tabindex="-1" href="#例子-134"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">13.361389</span> <span class="token number">38.115556</span> <span class="token string">"Palermo"</span> <span class="token number">15.087269</span> <span class="token number">37.502669</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOADD Sicily <span class="token number">12.758489</span> <span class="token number">38.788135</span> <span class="token string">"edge1"</span>   <span class="token number">17.241510</span> <span class="token number">38.788135</span> <span class="token string">"edge2"</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOSEARCH Sicily FROMLONLAT <span class="token number">15</span> <span class="token number">37</span> BYRADIUS <span class="token number">200</span> km ASC
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line">redis<span class="token operator">></span> GEOSEARCH Sicily FROMLONLAT <span class="token number">15</span> <span class="token number">37</span> BYBOX <span class="token number">400</span> <span class="token number">400</span> km ASC
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"Catania"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Palermo"</span>
</span><span class="code-line"><span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"edge2"</span>
</span><span class="code-line"><span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"edge1"</span>
</span></code></pre>
<p>查询表示地理空间索引的排序集，以获取框或圆区域内的成员。</p>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助-4"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助-4"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">













<table class="style-list"><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/geosearchstore">GEOSEARCHSTORE</a></td><td>查询表示地理空间索引的排序集以获取框或圆区域内的成员，并将结果存储在另一个键中</td></tr></tbody></table>
<!--rehype:className=style-list-->
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis超文本日志类型设置"><a aria-hidden="true" tabindex="-1" href="#redis超文本日志类型设置"><span class="icon icon-link"></span></a>Redis超文本日志类型设置</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pfadd"><a aria-hidden="true" tabindex="-1" href="#pfadd"><span class="icon icon-link"></span></a>PFADD</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">PFADD key element <span class="token punctuation">[</span>element <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-135"><a aria-hidden="true" tabindex="-1" href="#例子-135"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PFADD hll a b c d e f g
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PFCOUNT hll
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">7</span>
</span></code></pre>
<p>将指定的元素添加到指定的HyperLogLog。</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pfcount"><a aria-hidden="true" tabindex="-1" href="#pfcount"><span class="icon icon-link"></span></a>PFCOUNT</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">PFCOUNT key <span class="token punctuation">[</span>key <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-136"><a aria-hidden="true" tabindex="-1" href="#例子-136"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PFADD hll foo bar zap
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PFADD hll zap zap zap
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> PFADD hll foo bar
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> PFCOUNT hll
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span><span class="code-line">redis<span class="token operator">></span> PFADD some-other-hll <span class="token number">1</span> <span class="token number">2</span> <span class="token number">3</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PFCOUNT hll some-other-hll
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span></code></pre>
<p>返回HyperLogLog在键处观察到的集合的近似基数。</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="pfmerge"><a aria-hidden="true" tabindex="-1" href="#pfmerge"><span class="icon icon-link"></span></a>PFMERGE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">PFMERGE destkey sourcekey <span class="token punctuation">[</span>sourcekey <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-137"><a aria-hidden="true" tabindex="-1" href="#例子-137"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> PFADD hll1 foo bar zap a
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PFADD hll2 a b c foo
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">1</span>
</span><span class="code-line">redis<span class="token operator">></span> PFMERGE hll3 hll1 hll2
</span><span class="code-line"><span class="token string">"OK"</span>
</span><span class="code-line">redis<span class="token operator">></span> PFCOUNT hll3
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">6</span>
</span></code></pre>
<p>将N个不同的HyperLogLogs合并成一个。</p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="redis流命令"><a aria-hidden="true" tabindex="-1" href="#redis流命令"><span class="icon icon-link"></span></a>Redis流命令</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="一些引用可能有帮助-5"><a aria-hidden="true" tabindex="-1" href="#一些引用可能有帮助-5"><span class="icon icon-link"></span></a>一些引用(可能有帮助)</h3><div class="wrap-body">





































<table class="style-list"><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/xinfo">XINFO</a></td><td>获取有关流和消费者组的信息</td></tr><tr><td align="left"><a href="https://redis.io/commands/xdel">XDEL</a></td><td>从流中删除指定的条目。返回实际删除的项目数，如果某些 ID 不存在，则可能与传递的 ID 数不同</td></tr><tr><td align="left"><a href="https://redis.io/commands/xread">XREAD</a></td><td>返回多个流中从未见过的元素，其 ID 大于调用者为每个流报告的 ID</td></tr><tr><td align="left"><a href="https://redis.io/commands/xgroup">XGROUP</a></td><td>创建、销毁和管理消费者组</td></tr><tr><td align="left"><a href="https://redis.io/commands/xreadgroup">XREADGROUP</a></td><td>使用消费者组从流中返回新条目，或访问给定消费者的待处理条目的历史记录</td></tr><tr><td align="left"><a href="https://redis.io/commands/xclaim">XCLAIM</a></td><td>更改(或获取)消费者组中消息的所有权，就好像消息已传递给指定的消费者一样</td></tr><tr><td align="left"><a href="https://redis.io/commands/xpending">XPENDING</a></td><td>从流消费者组待定条目列表中返回信息和条目，这些信息是已获取但从未确认的消息</td></tr></tbody></table>
<!--rehype:className=style-list-->
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="xadd"><a aria-hidden="true" tabindex="-1" href="#xadd"><span class="icon icon-link"></span></a>XADD</h3><div class="wrap-body">
<pre><code class="code-highlight"><span class="code-line">XADD key [MAXLEN [=|~] length] [NOMKSTREAM] *|ID field value [field value ...]
</span></code></pre>
<h4 id="例子-138"><a aria-hidden="true" tabindex="-1" href="#例子-138"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XADD mystream * name Sara surname OConnor
</span><span class="code-line"><span class="token string">"1609040574632-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD mystream * field1 value1 field2 value2 field3 value3
</span><span class="code-line"><span class="token string">"1609040574632-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XLEN mystream
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">2</span>
</span><span class="code-line">redis<span class="token operator">></span> XRANGE mystream - +
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040574632-0"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"name"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Sara"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"surname"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"OConnor"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040574632-1"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"field1"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"value1"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"field2"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"value2"</span>
</span><span class="code-line">      <span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"field3"</span>
</span><span class="code-line">      <span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"value3"</span>
</span></code></pre>
<p>将新条目附加到流</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="xtrim"><a aria-hidden="true" tabindex="-1" href="#xtrim"><span class="icon icon-link"></span></a>XTRIM</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">XTRIM key MAXLEN <span class="token punctuation">[</span><span class="token operator">=</span><span class="token operator">|</span>~<span class="token punctuation">]</span> length
</span></code></pre>
<h4 id="例子-139"><a aria-hidden="true" tabindex="-1" href="#例子-139"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XADD mystream * field1 A field2 B field3 C field4 D
</span><span class="code-line"><span class="token string">"1609040575750-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XTRIM mystream MAXLEN <span class="token number">2</span>
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">0</span>
</span><span class="code-line">redis<span class="token operator">></span> XRANGE mystream - +
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040575750-0"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"field1"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"A"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"field2"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"B"</span>
</span><span class="code-line">      <span class="token number">5</span><span class="token punctuation">)</span> <span class="token string">"field3"</span>
</span><span class="code-line">      <span class="token number">6</span><span class="token punctuation">)</span> <span class="token string">"C"</span>
</span><span class="code-line">      <span class="token number">7</span><span class="token punctuation">)</span> <span class="token string">"field4"</span>
</span><span class="code-line">      <span class="token number">8</span><span class="token punctuation">)</span> <span class="token string">"D"</span>
</span></code></pre>
<p>将流修剪为(大约如果传递了“~”)特定大小</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="xrange"><a aria-hidden="true" tabindex="-1" href="#xrange"><span class="icon icon-link"></span></a>XRANGE</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">XRANGE key start end <span class="token punctuation">[</span>COUNT count<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-140"><a aria-hidden="true" tabindex="-1" href="#例子-140"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XADD writers * name Virginia surname Woolf
</span><span class="code-line"><span class="token string">"1609040578002-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Jane surname Austen
</span><span class="code-line"><span class="token string">"1609040578002-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Toni surname Morrison
</span><span class="code-line"><span class="token string">"1609040578003-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Agatha surname Christie
</span><span class="code-line"><span class="token string">"1609040578003-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Ngozi surname Adichie
</span><span class="code-line"><span class="token string">"1609040578003-2"</span>
</span><span class="code-line">redis<span class="token operator">></span> XLEN writers
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> XRANGE writers - + COUNT <span class="token number">2</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040578002-0"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"name"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Virginia"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"surname"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"Woolf"</span>
</span><span class="code-line"><span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040578002-1"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"name"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Jane"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"surname"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"Austen"</span>
</span></code></pre>
<p>返回流中的一系列元素，其 ID 与指定的 ID 间隔相匹配</p>
</div></div></div><div class="wrap h3body-exist row-span-2"><div class="wrap-header h3wrap"><h3 id="xrevrange"><a aria-hidden="true" tabindex="-1" href="#xrevrange"><span class="icon icon-link"></span></a>XREVRANGE</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-2-->
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">XREVRANGE key end start <span class="token punctuation">[</span>COUNT count<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-141"><a aria-hidden="true" tabindex="-1" href="#例子-141"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XADD writers * name Virginia surname Woolf
</span><span class="code-line"><span class="token string">"1609040579130-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Jane surname Austen
</span><span class="code-line"><span class="token string">"1609040579130-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Toni surname Morrison
</span><span class="code-line"><span class="token string">"1609040579130-2"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Agatha surname Christie
</span><span class="code-line"><span class="token string">"1609040579131-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD writers * name Ngozi surname Adichie
</span><span class="code-line"><span class="token string">"1609040579131-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XLEN writers
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">5</span>
</span><span class="code-line">redis<span class="token operator">></span> XREVRANGE writers + - COUNT <span class="token number">1</span>
</span><span class="code-line"><span class="token number">1</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"1609040579131-1"</span>
</span><span class="code-line">   <span class="token number">2</span><span class="token punctuation">)</span> <span class="token number">1</span><span class="token punctuation">)</span> <span class="token string">"name"</span>
</span><span class="code-line">      <span class="token number">2</span><span class="token punctuation">)</span> <span class="token string">"Ngozi"</span>
</span><span class="code-line">      <span class="token number">3</span><span class="token punctuation">)</span> <span class="token string">"surname"</span>
</span><span class="code-line">      <span class="token number">4</span><span class="token punctuation">)</span> <span class="token string">"Adichie"</span>
</span></code></pre>
<p>返回流中的一系列元素，ID 与指定的 ID 间隔相匹配，与 XRANGE 相比，顺序相反(从大到小的 ID)</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="xlen"><a aria-hidden="true" tabindex="-1" href="#xlen"><span class="icon icon-link"></span></a>XLEN</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">XLEN key
</span></code></pre>
<h4 id="例子-142"><a aria-hidden="true" tabindex="-1" href="#例子-142"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XADD mystream * item <span class="token number">1</span>
</span><span class="code-line"><span class="token string">"1609040580250-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD mystream * item <span class="token number">2</span>
</span><span class="code-line"><span class="token string">"1609040580250-1"</span>
</span><span class="code-line">redis<span class="token operator">></span> XADD mystream * item <span class="token number">3</span>
</span><span class="code-line"><span class="token string">"1609040580251-0"</span>
</span><span class="code-line">redis<span class="token operator">></span> XLEN mystream
</span><span class="code-line"><span class="token punctuation">(</span>integer<span class="token punctuation">)</span> <span class="token number">3</span>
</span></code></pre>
<p>返回流中的条目数</p>
</div></div></div><div class="wrap h3body-exist"><div class="wrap-header h3wrap"><h3 id="xack"><a aria-hidden="true" tabindex="-1" href="#xack"><span class="icon icon-link"></span></a>XACK</h3><div class="wrap-body">
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">XACK key group ID <span class="token punctuation">[</span>ID <span class="token punctuation">..</span>.<span class="token punctuation">]</span>
</span></code></pre>
<h4 id="例子-143"><a aria-hidden="true" tabindex="-1" href="#例子-143"><span class="icon icon-link"></span></a>例子</h4>
<pre class="language-shell"><code class="language-shell code-highlight"><span class="code-line">redis<span class="token operator">></span> XACK mystream mygroup <span class="token number">1526569495631</span>-0
</span><span class="code-line">ERR Unknown or disabled <span class="token builtin class-name">command</span> <span class="token string">'XACK'</span>
</span></code></pre>
<p>将待处理消息标记为已正确处理，有效地将其从消费者组的待处理条目列表中删除，该命令的返回值是成功确认的消息数，即我们实际能够在 <code>PEL</code> 中解析的 <code>ID</code></p>
</div></div></div></div></div><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="集群方面的东西"><a aria-hidden="true" tabindex="-1" href="#集群方面的东西"><span class="icon icon-link"></span></a>集群方面的东西</h2><div class="wrap-body">
<!--rehype:body-class=cols-2-->
</div></div><div class="h2wrap-body cols-2"><div class="wrap h3body-not-exist row-span-3"><div class="wrap-header h3wrap"><h3 id="节点集群"><a aria-hidden="true" tabindex="-1" href="#节点集群"><span class="icon icon-link"></span></a>节点、集群</h3><div class="wrap-body">
<!--rehype:wrap-class=row-span-3-->









































































































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/cluster-addslots">CLUSTER ADDSLOTS</a></td><td>为接收节点分配新的哈希槽</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-bumpepoch">CLUSTER BUMPEPOCH</a></td><td>提前集群配置纪元</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-count-failure-reports">CLUSTER COUNT-FAILURE-REPORTS</a></td><td>返回给定节点的活动故障报告数</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-countkeysinslot">CLUSTER COUNTKEYSINSLOT</a></td><td>返回指定哈希槽中本地键的个数</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-delslots">CLUSTER DELSLOTS</a></td><td>在接收节点中将哈希槽设置为未绑定</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-failover">CLUSTER FAILOVER</a></td><td>强制副本对其主副本执行手动故障转移</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-flushslots">CLUSTER FLUSHSLOTS</a></td><td>删除节点自身的slot信息</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-forget">CLUSTER FORGET</a></td><td>从节点表中删除一个节点</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-getkeysinslot">CLUSTER GETKEYSINSLOT</a></td><td>返回指定哈希槽中的本地键名</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-info">CLUSTER INFO</a></td><td>提供有关 Redis 集群节点状态的信息</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-keyslot">CLUSTER KEYSLOT</a></td><td>返回指定键的哈希槽</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-meet">CLUSTER MEET</a></td><td>强制节点集群与另一个节点握手</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-myid">CLUSTER MYID</a></td><td>返回节点id</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-nodes">CLUSTER NODES</a></td><td>获取节点的集群配置</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-replicate">CLUSTER REPLICATE</a></td><td>将节点重新配置为指定主节点的副本</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-reset">CLUSTER RESET</a></td><td>重置 Redis 集群节点</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-saveconfig">CLUSTER SAVECONFIG</a></td><td>强制节点将集群状态保存在磁盘上</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-set-config-epoch">CLUSTER SET-CONFIG-EPOCH</a></td><td>在新节点中设置配置纪元</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-setslot">CLUSTER SETSLOT</a></td><td>将哈希槽绑定到特定节点</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-slaves">CLUSTER SLAVES</a></td><td>列出指定主节点的副本节点</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-replicas">CLUSTER REPLICAS</a></td><td>列出指定主节点的副本节点</td></tr><tr><td align="left"><a href="https://redis.io/commands/cluster-slots">CLUSTER SLOTS</a></td><td>获取集群插槽数组到节点映射</td></tr><tr><td align="left"><a href="https://redis.io/commands/readonly">READONLY</a></td><td>为到集群副本节点的连接启用读取查询</td></tr><tr><td align="left"><a href="https://redis.io/commands/readwrite">READWRITE</a></td><td>禁用对集群副本节点连接的读取查询</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="交易"><a aria-hidden="true" tabindex="-1" href="#交易"><span class="icon icon-link"></span></a>交易</h3><div class="wrap-body">





























<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/discard">DISCARD</a></td><td>丢弃 MULTI 之后发出的所有命令</td></tr><tr><td align="left"><a href="https://redis.io/commands/exec">EXEC</a></td><td>执行 MULTI 之后发出的所有命令</td></tr><tr><td align="left"><a href="https://redis.io/commands/multi">MULTI</a></td><td>标记事务块的开始</td></tr><tr><td align="left"><a href="https://redis.io/commands/unwatch">UNWATCH</a></td><td>忘记所有监视的键</td></tr><tr><td align="left"><a href="https://redis.io/commands/watch">WATCH</a></td><td>观察给定的键以确定MULTI/EXEC块的执行</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="脚本"><a aria-hidden="true" tabindex="-1" href="#脚本"><span class="icon icon-link"></span></a>脚本</h3><div class="wrap-body">





































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/eval">EVAL</a></td><td>执行 Lua 脚本服务器端</td></tr><tr><td align="left"><a href="https://redis.io/commands/evalsha">EVALSHA</a></td><td>执行 Lua 脚本服务器端</td></tr><tr><td align="left"><a href="https://redis.io/commands/script-debug">SCRIPT DEBUG</a></td><td>为执行的脚本设置调试模式</td></tr><tr><td align="left"><a href="https://redis.io/commands/script-exists">SCRIPT EXISTS</a></td><td>检查脚本缓存中是否存在脚本</td></tr><tr><td align="left"><a href="https://redis.io/commands/script-flush">SCRIPT FLUSH</a></td><td>从脚本缓存中删除所有脚本</td></tr><tr><td align="left"><a href="https://redis.io/commands/script-kill">SCRIPT KILL</a></td><td>终止当前正在执行的脚本</td></tr><tr><td align="left"><a href="https://redis.io/commands/script-load">SCRIPT LOAD</a></td><td>将指定的 Lua 脚本加载到脚本缓存中</td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="发布操作"><a aria-hidden="true" tabindex="-1" href="#发布操作"><span class="icon icon-link"></span></a>发布操作</h3><div class="wrap-body">

































<table><thead><tr><th align="left">:-</th><th>--</th></tr></thead><tbody><tr><td align="left"><a href="https://redis.io/commands/psubscribe">PSUBSCRIBE</a></td><td>侦听发布到与给定模式匹配的频道的消息</td></tr><tr><td align="left"><a href="https://redis.io/commands/pubsub">PUBSUB</a></td><td>检查 Pub/Sub 子系统的状态</td></tr><tr><td align="left"><a href="https://redis.io/commands/publish">PUBLISH</a></td><td>向频道发布消息</td></tr><tr><td align="left"><a href="https://redis.io/commands/punsubscribe">PUNSUBSCRIBE</a></td><td>停止监听发布到与给定模式匹配的频道的消息</td></tr><tr><td align="left"><a href="https://redis.io/commands/subscribe">SUBSCRIBE</a></td><td>收听发布到给定频道的消息</td></tr><tr><td align="left"><a href="https://redis.io/commands/unsubscribe">UNSUBSCRIBE</a></td><td>停止收听发布到给定频道的消息</td></tr></tbody></table>
</div></div></div></div></div></div></div><footer class="footer-wrap"><footer class="max-container">© 2022 Kenny Wang.</footer></footer><script src="..\/data.js?v=1.4.1" defer></script><script src="..\/js/fuse.min.js?v=1.4.1" defer></script><script src="..\/js/main.js?v=1.4.1" defer></script><div id="mysearch"><div class="mysearch-box"><div class="mysearch-input"><div><svg xmlns="http://www.w3.org/2000/svg" height="1em" width="1em" viewBox="0 0 18 18">
  <path fill="currentColor" d="M17.71,16.29 L14.31,12.9 C15.4069846,11.5024547 16.0022094,9.77665502 16,8 C16,3.581722 12.418278,0 8,0 C3.581722,0 0,3.581722 0,8 C0,12.418278 3.581722,16 8,16 C9.77665502,16.0022094 11.5024547,15.4069846 12.9,14.31 L16.29,17.71 C16.4777666,17.8993127 16.7333625,18.0057983 17,18.0057983 C17.2666375,18.0057983 17.5222334,17.8993127 17.71,17.71 C17.8993127,17.5222334 18.0057983,17.2666375 18.0057983,17 C18.0057983,16.7333625 17.8993127,16.4777666 17.71,16.29 Z M2,8 C2,4.6862915 4.6862915,2 8,2 C11.3137085,2 14,4.6862915 14,8 C14,11.3137085 11.3137085,14 8,14 C4.6862915,14 2,11.3137085 2,8 Z"></path>
</svg><input id="mysearch-input" type="search" placeholder="搜索" autocomplete="off"><div class="mysearch-clear"></div></div><button id="mysearch-close" type="button">搜索</button></div><div class="mysearch-result"><div id="mysearch-menu"></div><div id="mysearch-content"></div></div></div></div></body>
</html>
